Re: question: NSThread & NSLock
Re: question: NSThread & NSLock
- Subject: Re: question: NSThread & NSLock
- From: Christian Stieber <email@hidden>
- Date: Mon, 29 May 2006 17:31:34 +0200
At 13:17 29.05.2006 +0200, Karim Morsy wrote:
I have multiple threads trying to access one critical section.
I protect that region with an NSLock. now, what I'm not sure about is...
when one thread holds the lock and let's say three other threads try
to acquire it while the first thread is still
inside the critical section, which of the waiting threads will get
access once the first thread unlocks ?
are the threads waiting in a queue, is one thread chosen randomly or
by priority ?
The theory behind threads und locks says that a thread is
chosen randomly; whatever the current implementation is
doing, it might be different next version.
However, in general, if you have a need to force threads into
a specific execution order, most likely you don't actually
want multiple threads. Instead, you're probably better off
using a single thread and a "task queue": if you want something
done, stick it to the end of the task queue. The thread loops,
taking the front element from the queue and processing it.
That way, you can rearrange the task queue in whatever way
you wish (except for the element that's currently being
processed), and you don't have to worry about "I have 3
threads waiting on the lock and want to make sure thread
2 gets the lock next".
Christian
_______________________________________________
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