question: NSThread & NSLock
question: NSThread & NSLock
- Subject: question: NSThread & NSLock
- From: Karim Morsy <email@hidden>
- Date: Mon, 29 May 2006 13:17:10 +0200
Hi,
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 ?
what I'm doing is the following:
one thread is loading audio data (it acquires an nslock for the
critical section where loading and initialization is done). if a user
choses a different audio file, while one thread is still loading it
should stop, clean up and release the lock (I have a global BOOL
"shouldStopInit" variable which the thread that's currently loading
periodically checks at the end of each loop).
now, the problem is when one thread sets shouldStopInit to YES and
tries to get the lock. the currently working thread does the cleaning
up and before it unlocks
a third thread sets shouldStopInit to YES and tries to acquire the
lock. how can I make sure that the last thread that tries to enter
will be solely allowed to do so (any previous ones that haven't
started should be ignored)?
many thanks in advance,
Karim
_______________________________________________
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