The elementary methods adopted by classes that define lock objects.


protocol NSLocking


A lock object is used to coordinate the actions of multiple threads of execution within a single application. By using a lock object, an application can protect critical sections of code from being executed simultaneously by separate threads, thus protecting shared data and other shared resources from corruption.


Working with Locks

func lock()

Attempts to acquire a lock, blocking a thread’s execution until the lock can be acquired.


func unlock()

Relinquishes a previously acquired lock.


See Also

Threads and Locking

class Thread

A thread of execution.

class NSLock

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

class NSRecursiveLock

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

class NSDistributedLock

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

class NSConditionLock

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

class NSCondition

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