How to kill a camping kqueue thread? Was: close() hangs … in 10.5 only
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Thank you, Terry. Fortunately for my feeble brain the problem was none of the rocket science you explained, just this one: On 2010 Aug 16, at 17:38, Terry Lambert wrote:
you have another thread camping out on the fd in kevent().
Indeed, my app operates by creating a kqueue in the main thread with kevent(…,EV_ADD|EV_ENABLE,…), and then spinning off a new thread via -[NSThread detachNewThreadSelector:::]. The new thread camps out on kevent() in a loop like this: while(true) { result = kevent(....) ; if (result != -1) { if(event.filter == EVFILT_VNODE) { // Filesystem event has occurred /* Create NSNotification */ /* Send NSNotification on main thread */ } } else { break ; } } // Thread exits return ; Now when my app is done with this kqueue, I delete it in the main thread with kevent(…,EV_DELETE|EV_DISABLE,…). When running in Mac OS 10.6, this causes kevent() in the secondary thread to return -1, which causes my secondary thread there to break out of its loop and exit. But when running in Mac OS 10.5, deleting the kqueue does *not* cause kevent() in the secondary thread to return. It just stays camped out. This 10.6 behavior of kevent(), to return -1 when its kqueue is deleted, does not seem to be documented. Maybe I discovered it by accident. So, the solution you suggested is to kill my camper thread. To do that I would need to rewrite using pthread_create() et al since NSThread has no equivalents to pthread_self() or pthread_kill() as far as I can see. But Apple's Threading Programming Guide recommends against killing threads. Many apps need to do other work while waiting for a filesystem event, and spinning off a camper thread seems natural. So, before re-coding with pthread_kill() I thought I'd ask if there is a better way to do this? Thank you, Jerry _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
Jerry Krinock