Copyright ©1995 by NeXT Computer, Inc.  All Rights Reserved.

NXSpinLock



Inherits From: Object
Conforms To: NXLock
Declared In: machkit/NXLock.h



Class Description

An NXSpinLock is used to lock short sections of code that take very little time to execute.  A lock is created once and is subsequently used to protect one or more regions of code.  If a region of code is in use, an NXSpinLock will busy-wait until the lock is released.  An NXSpinLock can be acquired very quickly, but will consume CPU resources as long as the lock is held by another party.  The following example shows the use of an NXSpinLock:

NXSpinLock *theLock = [[NXSpinLock alloc] init];
// done once!
/* ... other code */
[theLock lock];
/* ... short quick section of atomic code... */
[theLock unlock];

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.



Instance Variables

None declared in this class.



Method Types

Acquire or release a lock lock
unlock



Instance Methods

lock
lock

Uses mutex_lock() to busy-wait until the lock isn't in use and grab the lock.



unlock
unlock

Releases the lock with mutex_unlock(), allowing the next party to access the critical section of code.