Attempts to acquire a lock on the context.
- iOS 3.0–8.0Deprecated
- macOS 10.4–10.10Deprecated
- UIKit for Mac 13.0–13.0Deprecated
- Core Data
This method blocks a thread’s execution until the lock can be acquired. 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 past, the thread relinquishes the lock by invoking
Sending this message to a managed object context helps the framework to understand the scope of a transaction in a multi-threaded environment. It is preferable to use the
NSManaged’s implementation of
NSLocking instead using of a separate mutex object.
If you lock (or successfully
try) a managed object context, the thread in which the lock call is made must keep a strong reference to the context until it invokes unlock, otherwise if the context is deallocated this will result in deadlock.