|[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]|
On 29/05/2006, at 9:17 PM, 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 ?
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)?
Description: S/MIME cryptographic signature
_______________________________________________ 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
|>question: NSThread & NSLock (From: Karim Morsy <email@hidden>)|
Visit the Apple Store online or at retail locations.
Copyright © 2011 Apple Inc. All rights reserved.