Are nested synchronized blocks allowed in Objective-C? Are nested synchronized blocks allowed in Objective-C? multithreading multithreading

Are nested synchronized blocks allowed in Objective-C?


Yes, they are. From the docs (now retired):

The Objective-C synchronization feature supports recursive and reentrant code. A thread can use a single semaphore several times in a recursive manner; other threads are blocked from using it until the thread releases all the locks obtained with it; that is, every @synchronized() block is exited normally or through an exception.

For a discussion of performance with this and other methods of synchronization/locking, see here.