Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are nested synchronized blocks allowed in Objective-C?

Tags:

I read in this article that in Java, nested synchronised blocks are allowed. I know that Objective-C's synchronised blocks look a lot like Java's. So I wonder: Are nested blocks allowed in Objective-C?

I also have a side question: Is there a practical limit on recursive blocks?

Thank you for your speedy answer!

like image 699
Constantino Tsarouhas Avatar asked Aug 13 '11 18:08

Constantino Tsarouhas


1 Answers

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.

like image 188
jtbandes Avatar answered Sep 22 '22 01:09

jtbandes