Re: NSLock locking order;
Re: NSLock locking order;
- Subject: Re: NSLock locking order;
- From: John Stiles <email@hidden>
- Date: Thu, 10 Nov 2005 10:54:34 -0800
If there are multiple threads blocked on a resource--like your lock--
I think the kernel attempts to give each thread an equal opportunity
to grab it. I don't know if there are any hard and fast guarantees.
In practice I don't think you will see one thread being completely
starved out unless there is a bug somewhere.
On Nov 10, 2005, at 10:37 AM, Matt Budd (Madentec) wrote:
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:
40blizzard.com
This email sent to email@hidden
_______________________________________________
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