Copyright ©1995 by NeXT Computer, Inc. All Rights Reserved.
|An NXRecursiveLock locks a critical section of code such that a single thread can reaquire the lock multiple times without deadlocking, while preventing access by other threads. Note that this implies that a recursive lock will not protect a critical section from a signal handler interrupting the thread holding the lock. Here is an example where a recursive lock functions properly but other lock types would deadlock:|
// create the lock only once!
NXRecursiveLock *theLock = [[NXRecursiveLock alloc] init];
/* ... other code */
/* ... possibly a long time of fussing with global data... */
[theLock lock]; //possibly invoked in a subroutine
|The NXConditionLock, NXLock, NXRecursiveLock, and NXSpinLock classes all implement the NXLock protocol with various features and performance characteristics; see the other class descriptions for more information.|
|None declared in this class.|
|Acquire or release a lock||lock|
|Waits until the lock isn't in use by another thread, then grabs the lock and increments an internal counter indicating how many times the lock is held by the current thread.|
|Decrements the internal count indicating how many times the lock is held by the current thread. If the lock is no longer in use by the thread, it is released for use by the next requestor.|