Class

NSLock

An object that coordinates the operation of multiple threads of execution within the same application.

Declaration

@interface NSLock : NSObject

Overview

An NSLock object can be used to mediate access to an application’s global data or to protect a critical section of code, allowing it to run atomically.

You should not use this class to implement a recursive lock. Calling the lock method twice on the same thread will lock up your thread permanently. Use the NSRecursiveLock class to implement recursive locks instead.

Unlocking a lock that is not locked is considered a programmer error and should be fixed in your code. The NSLock class reports such errors by printing an error message to the console when they occur.

Topics

Acquiring a Lock

- lockBeforeDate:

Attempts to acquire a lock before a given time and returns a Boolean value indicating whether the attempt was successful.

- tryLock

Attempts to acquire a lock and immediately returns a Boolean value that indicates whether the attempt was successful.

Naming the Lock

name

The name associated with the receiver.

Relationships

Inherits From

Conforms To

See Also

Threads and Locking

NSThread

A thread of execution.

NSLocking

The elementary methods adopted by classes that define lock objects.

NSRecursiveLock

A lock that may be acquired multiple times by the same thread without causing a deadlock.

NSDistributedLock

A lock that multiple applications on multiple hosts can use to restrict access to some shared resource, such as a file.

NSConditionLock

A lock that can be associated with specific, user-defined conditions.

NSCondition

A condition variable whose semantics follow those used for POSIX-style conditions.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software