[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: An acutal NSLock bug
From: |
Alexander Malmberg |
Subject: |
Re: An acutal NSLock bug |
Date: |
Thu, 20 Oct 2005 23:07:12 +0200 |
User-agent: |
Debian Thunderbird 1.0.2 (X11/20050602) |
Adam Fedor wrote:
> That being said, I could see how this type of usage could be
> beneficial. Although I do not know if the underlying thread mechanism
> supports this. I would suspect Condition Locks to be better used
> here (Unfortunately, GNUstep has the same limitation with
> NSConditonLock locks, which I am definitely more inclined to change,
> if it is possible using the underlying thread mechanism).
This isn't really a limitation when using NSConditionLock:s (and I
believe the behavior is intentional), it just makes it a bit less
obvious how to do this. What you need is something like (untested):
lock = [[NSConditionLock alloc] initWithCondition: 1];
...
numprocesses=99;
while (numprocesses >= 0)
{
[lock lockWhenCondition: 1];
[lock unlockWithCondition: 0];
[NSThread detachNewThreadSelector:@selector(doProcess:)
toTarget:anObject
withObject:anotherObject];
numprocesses --;
}
...
-(void) doProcess: ...
{
[lock lockWhenCondition: 0];
[lock unlockWithCondition: 1];
...
}
- Alexander Malmberg