O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required