Mac Developer Library

Developer

Foundation Framework Reference NSRecursiveLock Class Reference

Options
Deployment Target:

On This Page
Language:

NSRecursiveLock

NSRecursiveLock defines a lock that may be acquired multiple times by the same thread without causing a deadlock, a situation where a thread is permanently blocked waiting for itself to relinquish a lock. While the locking thread has one or more locks, all other threads are prevented from accessing the code protected by the lock.

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.0 and later.
  • Attempts to acquire a lock before a given date.

    Declaration

    Swift

    func lockBeforeDate(_ limit: NSDate) -> Bool

    Objective-C

    - (BOOL)lockBeforeDate:(NSDate *)limit

    Parameters

    limit

    The time before which the lock should be acquired.

    Return Value

    YEStrue if the lock is acquired before limit, otherwise NOfalse.

    Discussion

    The thread is blocked until the receiver acquires the lock or limit is reached.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func tryLock() -> Bool

    Objective-C

    - (BOOL)tryLock

    Return Value

    YEStrue if successful, otherwise NOfalse.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • name name Property

    The name associated with the receiver.

    Declaration

    Swift

    var name: String?

    Objective-C

    @property(copy) NSString *name

    Discussion

    You can use a name string to identify a lock within your code. Cocoa also uses this name as part of any error descriptions involving the receiver.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.5 and later.