[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: An acutal NSLock bug
From: |
Adam Fedor |
Subject: |
Re: An acutal NSLock bug |
Date: |
Thu, 20 Oct 2005 13:43:47 -0600 |
On 2005-10-20 12:56:22 -0600 Morgan Giddings <giddings@unc.edu> wrote:
>
> numprocesses=99;
> while (numprocesses >= 0) {
> [myLock lock];
> [NSThread detachNewThreadSelector:@selector(doProcess:)
> toTarget:anObject
> withObject:anotherObject];
> numprocesses --;
> }
>
Well, I think you are still using an undocumented feature of the locking code.
For instance, the Apple documentation has this to say:
Important: Many mutex locking mechanisms are designed to return an error if a
thread tries to acquire a mutex it already owns. Such an action could deadlock
the thread and should be avoided. If your thread needs to acquire the same lock
multiple times, you should use a recursive lock, as described in “Recursive
Locks”.
http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/index.html#//apple_ref/doc/uid/10000057i
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).