kqueues and Runloops
You can use kqueues in your Cocoa and Carbon applications to monitor OS events of interest by making a thread that sits on kevent(), or you can use the runloop.
You can create a thread that contains the kevent() call. If given no timeout, kevent() will block the thread until something interesting happens. That thread, after it wakes up, can notify the application’s main thread about what happened or do whatever work is appropriate.
It is safe, though, to manipulate a file descriptor in one thread while another thread is monitoring it with a kqueue. If the file is closed, the kernel atomically removes any pending events associated with this file descriptor in the process. However, there is one gotcha. If a file descriptor ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access