• 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
NSLock locking order;
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSLock locking order;


  • Subject: NSLock locking order;
  • From: "Matt Budd (Madentec)" <email@hidden>
  • Date: Thu, 10 Nov 2005 11:37:15 -0700

Hello all,

Say I have three threads competing for the same NSLock. Here's some small psuedo code:

Thread A, B, and C (just with different "<stuff>")
--------------------------------------------------------------
while (YES) {
[_oLock lock];
<stuff>
[_oLock unlock];
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
}


So lets say thread A got the the lock first, and then then got swapped out while doing "<stuff>". Then thread B blocks attempting to acquire the lock. Then thread C runs and also blocks attempting to acquire the lock. Then we get back to thread A and it finishes its "<stuff>", unlocks the _oLock, and sleeps for half a second.

Is there any order to who will get to acquire the lock next? Does thread B get it because it is queued up somewhere in the foundation's NSLock class that it is first? Or is there a possibility that thread A might finish its sleep and loop around and obtain the lock again? Or does thread C have a chance?

Thanks for any info...
 - Matt

_______________________________________________
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: NSLock locking order;
      • From: Joseph Kelly <email@hidden>
    • Re: NSLock locking order;
      • From: Shawn Erickson <email@hidden>
    • Re: NSLock locking order;
      • From: John Stiles <email@hidden>
  • Prev by Date: Why can adding an KVO call didChangeValueForKey:
  • Next by Date: Re: NSLock locking order;
  • Previous by thread: Why can adding an KVO call didChangeValueForKey:
  • Next by thread: Re: NSLock locking order;
  • Index(es):
    • Date
    • Thread