• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
question: NSThread & NSLock
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: question: NSThread & NSLock
      • From: Christian Stieber <email@hidden>
    • Re: question: NSThread & NSLock
      • From: Chris Suter <email@hidden>
  • Prev by Date: NSError naming convention?
  • Next by Date: Re: question: NSThread & NSLock
  • Previous by thread: Re: NSError naming convention?
  • Next by thread: Re: question: NSThread & NSLock
  • Index(es):
    • Date
    • Thread