# NSLock class reference

csdavec@swan.ac.uk
Generated at 2025-12-02 21:52:00 +0000
1996-2010 Free Software Foundation, Inc.
Software documentation for the NSCondition class
Foundation/NSLock.h
NSLocking
NSCondition provides an interface to POSIX condition variables.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
broadcast
Wakes all threads that are waiting on this condition.
name
Returns the name used for debugging messages.
setName:
newName
Sets the name used for debugging messages.
signal
Wakes wany one of the threads that are waiting on this condition.
wait
Blocks and atomically unlocks the receiver. This method should only be called when the receiver is locked. The caller will then block until the receiver is sent either a -signal or -broadcast message from another thread. At which point, the calling thread will reacquire the lock.
waitUntilDate:
limit
Blocks the calling thread and acquires the lock, in the same way as -wait . Returns `YES` if the condition is signaled, or `NO` if the timeout is reached.
Software documentation for the NSConditionLock class
Foundation/NSLock.h
NSLocking
Lock that allows user to request it only when an internal integer condition is equal to a particular value. The condition is set on initialization and whenever the lock is relinquished.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
condition
Return the current condition of the lock.
initWithCondition:
value
Initialize lock with given condition.
isLockedByCurrentThread
Report whether this lock is held by the current thread.
Raises an exception if this is not supported by the system lock mechanism.
lock
Block until acquiring lock.
lockBeforeDate:
limit
Try to acquire lock and return before limit, `YES` if succeeded, `NO` if not.
lockWhenCondition:
value
Acquire lock when it is available and the internal condition is equal to value. Blocks until this occurs.
lockWhenCondition:
condition_to_meet
beforeDate:
limitDate
Try to acquire lock, when internal condition is equal to condition_to_meet, and return before limit, `YES` if succeeded, `NO` if not.
name
Return the name of the receiver or `nil` of none has been set.
setName:
name
Sets the name of the receiver (for use in debugging).
tryLock
Try to acquire lock regardless of condition and return immediately, `YES` if succeeded, `NO` if not.
tryLockWhenCondition:
value
Try to acquire lock if condition is equal to value and return immediately in any case, `YES` if succeeded, `NO` if not.
unlock
Relinquish lock.
unlockWithCondition:
value
Relinquish the lock, setting internal condition to value.
Software documentation for the NSLock class
Foundation/NSLock.h
NSLocking

Simplest lock for protecting critical sections of code.

An `NSLock` is used in multi-threaded applications to protect critical pieces of code. While one thread holds a lock within a piece of code, another thread cannot execute that code until the first thread has given up its hold on the lock. The limitation of `NSLock` is that you can only lock an `NSLock` once and it must be unlocked before it can be acquired again.
Other lock classes, notably NSRecursiveLock, have different restrictions.

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
isLockedByCurrentThread
Report whether this lock is held by the current thread.
Raises an exception if this is not supported by the system lock mechanism.
lock
Block until acquiring lock.
lockBeforeDate:
limit
Try to acquire lock and return before limit, `YES` if succeeded, `NO` if not.
name
Return the name of the receiver or `nil` of none has been set.
setName:
name
Sets the name of the receiver (for use in debugging).
tryLock
Try to acquire lock and return immediately, `YES` if succeeded, `NO` if not.
unlock
Relinquish lock.
Software documentation for the NSRecursiveLock class
Foundation/NSLock.h
NSLocking
Allows the lock to be recursively acquired by the same thread. If the same thread locks the mutex (n) times then that same thread must also unlock it (n) times before another thread can acquire the lock.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
isLockedByCurrentThread
Report whether this lock is held by the current thread.
Raises an exception if this is not supported by the system lock mechanism.
lock
Block until acquiring lock.
lockBeforeDate:
limit
Try to acquire lock and return before limit, `YES` if succeeded, `NO` if not.
name
Return the name of the receiver or `nil` of none has been set.
setName:
name
Sets the name of the receiver (for use in debugging).
tryLock
Try to acquire lock regardless of condition and return immediately, `YES` if succeeded, `NO` if not.
unlock
Relinquish lock.
Software documentation for the NSObject(GSTraceLocks) informal protocol
Foundation/NSLock.h
Controls tracing of locks for deadlocking.
shouldCreateTraceableLocks:
shouldTrace
Sets whether newly created lock objects (NSCondition, NSConditionLock, NSLock, NSRecursiveLock but NOT NSDistributedLock) should be created so that their use by threads is traced and deadlocks can be detected.
Returns the old value of the setting.
tracedCondition
Creates and returns a single autoreleased traced condition.
tracedConditionLockWithCondition:
value
Creates and returns a single autoreleased traced condition lock.
tracedLock
Creates and returns a single autoreleased traced lock.
tracedRecursiveLock
Creates and returns a single autoreleased traced recursive lock.
Software documentation for the NSLocking protocol
Foundation/NSLock.h
Protocol defining lock and unlock operations.
lock
Block until acquiring lock.
unlock
Relinquish lock.