NSRecursiveLock Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in iOS 2.0 and later.
Companion guide
Declared in
NSLock.h

Overview

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.

Adopted Protocols

NSLocking

Tasks

Acquiring a Lock

Naming the Lock

Instance Methods

lockBeforeDate:

Attempts to acquire a lock before a given date.

- (BOOL)lockBeforeDate:(NSDate *)limit
Parameters
limit

The time before which the lock should be acquired.

Return Value

YES if the lock is acquired before limit, otherwise NO.

Discussion

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

Availability
  • Available in iOS 2.0 and later.
Declared In
NSLock.h

name

Returns the name associated with the receiver.

- (NSString *)name
Return Value

The name of the receiver.

Availability
  • Available in iOS 2.0 and later.
See Also
Declared In
NSLock.h

setName:

Assigns a name to the receiver

- (void)setName:(NSString *)newName
Parameters
newName

The new name for the receiver. This method makes a copy of the specified string.

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.

Availability
  • Available in iOS 2.0 and later.
See Also
Declared In
NSLock.h

tryLock

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

- (BOOL)tryLock
Return Value

YES if successful, otherwise NO.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSLock.h