On Tue, Nov 25, 2008 at 11:31 AM, Scott Ribe <[EMAIL PROTECTED]> wrote: >> I'm new to thread programming. I need to kill the thread in a void function. > > Let the function end. It's that simple. > >> How can I do this? > > You can't just kill a thread. You can let the function return when it's > finished. You can arrange some way to signal it to exit, and have it return > when it sees the signal (and this includes the POSIX function to "kill" a > thread). But there is no function to simply terminate one thread from > another, because there is NO WAY to create a function to do that safely.
Actually there is such a function. Check out pthread_setcanceltype() and the PTHREAD_CANCEL_ASYNCHRONOUS option, which does exactly that when used in conjunction with the pthread_cancel() function. However you should pretty much never use this. It is extremely difficult to write asynchronous-cancel-safe code. Among other things, you must disable thread cancellation before invoking *any* external code that isn't guaranteed to be cancel-safe (which is basically all of it), including things like objc_msgSend which means you can't safely do any ObjC messaging while cancellation is enabled. Thread cancellation is available but it's very bad mojo and is rarely the correct solution to anything, pretty much as you said. Mike _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]