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


@interface NSConditionLock : NSObject


Using an NSConditionLock object, you can ensure that a thread can acquire a lock only if a certain condition is met. Once it has acquired the lock and executed the critical section of code, the thread can relinquish the lock and set the associated condition to something new. The conditions themselves are arbitrary: you define them as needed for your application.


Initializing an NSConditionLock Object

- initWithCondition:

Initializes a newly allocated NSConditionLock object and sets its condition.

Accessing the Condition


The condition associated with the receiver.

Acquiring and Releasing a Lock

- lockBeforeDate:

Attempts to acquire a lock before a specified moment in time.

- lockWhenCondition:

Attempts to acquire a lock.

- lockWhenCondition:beforeDate:

Attempts to acquire a lock before a specified moment in time.

- tryLock

Attempts to acquire a lock without regard to the receiver’s condition.

- tryLockWhenCondition:

Attempts to acquire a lock if the receiver’s condition is equal to the specified condition.

- unlockWithCondition:

Relinquishes the lock and sets the receiver’s condition.

Identifying the Condition Lock


The name associated with the receiver.


Inherits From

Conforms To

See Also

Threads and Locking


A thread of execution.


The elementary methods adopted by classes that define lock objects.


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


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


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


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