Re: using select() without blocking the runloop

Chris Hanson

On Nov 24, 2017, at 1:36 AM, Roland King <rols@...> wrote:

yes of course file handles are thread-specific, you wouldn’t want random bits of code trying 0, 1, 2 … to see what it could get. Actually they are process-specific, but the process running your dispatch queue threads is not you and even if it was you the threads were probably created before you created the filehandles so it wouldn’t have inherited them. 

Neither of these statements is correct:

(1) File handles are per-process, not per-thread. It’s the developer’s responsibility not to try to manipulate the same file handle from multiple threads at the same time. They’re shared across a fork() and can be shared across a posix_spawn(), which is how stdin/stdout/stderr is set up in a child process by its parent, but in general this isn’t something an application developer has to worry about. (NSTask deals with all of the gory details of ensuring all of your descriptors don’t get shared to any spawned tasks, only the stdin/stdout/stderr you set.)

(2) Dispatch queue threads are not run in a different process than they’re used from. This doesn’t even really make sense, since if they were in different processes they wouldn’t be sharing memory without using some explicit shared-memory API, and “__block” doesn’t do that.

  -- Chris

Join to automatically receive all group messages.