Re: Yielding an NSThread-started thread
Re: Yielding an NSThread-started thread
- Subject: Re: Yielding an NSThread-started thread
- From: John Stiles <email@hidden>
- Date: Tue, 21 Nov 2006 08:52:15 -0800
You can just call usleep() to give up your quantum for as long as you
want. There may be a Cocoa equivalent call but it's not occurring to me
at the moment :)
If you want to be awakened in the future when a certain event occurs,
you can use Posix semaphores for this, or NSLocks.
Alastair Houghton wrote:
On 21 Nov 2006, at 13:11, Philip Q wrote:
Is there a recommended/good way to yield a thread started using
NSThread while it waits for another?
pthread has pthread_yield(), libc has sched_yield(), Thread Manager
has YieldToAnyThread(), Multiprocessing Services has MPYield() -- but
I don't see a Cocoa one, and I don't know what the unexpected
consequences might be of calling one from another library?
If you read the documentation, you'll see that NSThread is layered on
top of POSIX threads, so you can safely call pthread_yield().
Generally speaking, however, you wouldn't want to do that; it's much
better to signal a thread explicitly using a condition variable, a
mutex or some other kind of synchronisable object. Is there some
reason that you can't do that in your case?
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden