Mac Developer Library

Developer

Foundation Framework Reference NSLocking Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSLocking

The NSLocking protocol declares the elementary methods adopted by classes that define lock objects. 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.

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.0 and later.
  • lock() - lock Required

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

    Declaration

    Swift

    func lock()

    Objective-C

    - (void)lock

    Discussion

    An application protects a critical section of code by requiring a thread to acquire a lock before executing the code. Once the critical section is completed, the thread relinquishes the lock by invoking unlock.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • unlock() - unlock Required

    Relinquishes a previously acquired lock. (required)

    Declaration

    Swift

    func unlock()

    Objective-C

    - (void)unlock

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.