Re: NSCondition (unlocked when not locked)
Re: NSCondition (unlocked when not locked)
- Subject: Re: NSCondition (unlocked when not locked)
- From: Greg Guerin <email@hidden>
- Date: Fri, 10 Jul 2009 09:25:28 -0700
Torsten Curdt wrote:
while (!quit) {
[pollingCondition lock];
[pollingCondition waitUntilDate: [NSDate
dateWithTimeIntervalSinceNow:SLEEP]];
[pollingCondition unlock];
...
}
...
}
Is it OK to do it like that? Is there a better way?
You're not following the pattern laid out in the Overview setion of
the NSCondition class reference. In particular, you don't have a
boolean predicate, and you're not doing the task's work between the
bounds of lock and unlock.
http://developer.apple.com/documentation/Cocoa/Reference/
NSCondition_class/Reference/Reference.html
"A boolean predicate is an important part of the semantics of using
conditions because of the way signaling works. Signaling a condition
does not guarantee that the condition itself is true. There are
timing issues involved in signaling that may cause false signals to
appear. Using a predicate ensures that these spurious signals do not
cause you to perform work before it is safe to do so. The predicate
itself is simply a flag or other variable in your code that you test
in order to acquire a Boolean result."
Also, quoted from the "Threading Programming Guide" linked to from
NSCondition's class reference.
"The correct implementation of conditions requires careful coding,
however, so you should look at the examples in “Using Conditions”
before using them in your own code."
-- GG
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden