NSCondition (unlocked when not locked)
NSCondition (unlocked when not locked)
- Subject: NSCondition (unlocked when not locked)
- From: Torsten Curdt <email@hidden>
- Date: Fri, 10 Jul 2009 13:50:00 +0200
Hey folks,
I have a worker thread that is only slowly polling. I would like to be
able wake him up from a different thread though. A bit like the
select(2) pattern. So what I do is:
...
pollingCondition = [[NSCondition alloc] init];
...
- (void) pollNow
{
[pollingCondition lock];
[pollingCondition signal];
[pollingCondition unlock];
}
- (void) workerThread:(id)arg
...
while (!quit) {
[pollingCondition lock];
[pollingCondition waitUntilDate: [NSDate
dateWithTimeIntervalSinceNow:SLEEP]];
[pollingCondition unlock];
...
}
...
}
Is it OK to do it like that? Is there a better way?
I've seen an "unlocked when not locked" and don't understand how this
could happen.
cheers
--
Torsten
_______________________________________________
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