Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: question on pthread (from unix-porting)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question on pthread (from unix-porting)



I created a thread that calls CGWaitForScreenRefreshRects. From the main thread I want to signal this thread to die with a pthread_cancel. If I wait on the thread with a pthread_join, I get a semaphore_wait_trap.

semaphore_wait_trap() is a kernel call that is waiting for a signal on a semaphore. This is normal behavior for pthread_join().


pthread_cancel() does not cause arbitrary routines in the target thread to unblock and return. In Darwin currently, cancellation is "requested" on a thread, and a thread can check to see if has been requested to cancel and act upon it by calling pthread_testcancel(). It is required that the routine naturally progress to the pthread_testcancel() call, as pthread_cancel() merely sets a bit in the thread's data structure to indicate the intent to cancel -- it does not interrupt the running thread.

All this may change in the future to be more aligned with the POSIX specification for pthread_cancel() behavior*, so for now I'd suggest avoiding pthread_cancel() in current Darwin and OS X releases, and finding an alternate way to make your threads exit themselves gracefully.

matt.

[*] Even if pthread_cancel() did behave as POSIX specified, there would be no guarantee that any non-POSIX frameworks (like CoreGraphics) would be tolerant of or comply with cancellation requests.
_______________________________________________
unix-porting mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/unix-porting
Do not post admin requests to the list. They will be ignored.






Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.