Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights Reserved.

NSLock

Inherits From: NSObject

Conforms To: NSLocking NSObject (NSObject)

Declared In: Foundation/NSLock.h

Class Description

An NSLock is used to protect critical regions of code. 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 NSLock waits using the condition_wait() function, so the thread doesn't busy-wait. The following example shows the use of an NSLock with the methods lock and unlock defined in the NSLocking protocol:

NSLock *theLock = [NSLock new]; // done once!

/* ... other code */

[theLock lock];

/* ... possibly a long time of fussing with global data... */

[theLock unlock];

The NSConditionLock, NSLock, and NSRecursiveLock classes all implement the NSLocking protocol with various features and performance characteristics; see the other class descriptions for more information.

Acquiring a Lock