Re: NSCondition (unlocked when not locked)
Re: NSCondition (unlocked when not locked)
- Subject: Re: NSCondition (unlocked when not locked)
- From: Benjamin Stiglitz <email@hidden>
- Date: Fri, 10 Jul 2009 13:49:32 -0400
- Mail-followup-to: Cocoa Developers <email@hidden>
> > What’s the value of SLEEP? -waitUntilDate: can return NO indicating that the
> > timeout elapsed and the lock is not locked; you probably want -wait.
>
> No, I do want the waitUntilDate because I do not solely want to wait
> for the signal.
In that case you probably want to use an NSConditionLock with all the
conditions you would like to wake up for; better than polling for
whatever else you’re doing except in the very specific case of a task
which actually needs to be performed at a given interval (though the way
the code is structured right now may end up running your other tasks
more often than SLEEP).
> So you are saying it should rather be like this?
>
> while (!quit) {
> [pollingCondition lock];
>
> if([pollingCondition waitUntilDate:
> [NSDate dateWithTimeIntervalSinceNow:SLEEP]]) {
>
> [pollingCondition unlock];
>
> }
> ...
> }
>
> I can't seem to find that indicated in the documentation though.
>
> http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/NSCondition_class/Reference/Reference.html
>
> Also the documentation suggests that after calling
>
> [pollingCondition lock];
>
> the contract is to have a lock for sure.
You know, you’re right. I was thinking of the way that NSConditionLock
behaves here (do you see a pattern?). Sorry for the bad advice—how
embarrassing.
Greg Guerin’s advice is helpful, and is yet another thing shoving you
toward NSConditionLock (it manages the boolean—or
higher-cardinality—condition). It doesn’t explain why the lock was
complaining about being unlocked; did you try breaking on _NSLockError
like the log message suggests? Are you perhaps reinitializing the
pollingCondition from another thread?
-Ben
_______________________________________________
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