NSLock object is used to coordinate the operation of multiple threads of execution within the same application. An
NSLock object can be used to mediate access to an application’s global data or to protect a critical section of code, allowing it to run atomically.
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
You should not use this class to implement a recursive lock. Calling the
lock method twice on the same thread will lock up your thread permanently. Use the
NSRecursive class to implement recursive locks instead.
Unlocking a lock that is not locked is considered a programmer error and should be fixed in your code. The
NSLock class reports such errors by printing an error message to the console when they occur.