max_ max_ - 4 months ago 33
iOS Question

What does @synchronized() do?

I just created a singleton method, and I would like to know what the function

does, as I use it frequently, but do not know the meaning.


It declares a critical section around the code block. In multithreaded code, @synchronized guarantees that only one thread can be executing that code in the block at any given time.

If you aren't aware of what it does, then your application probably isn't multithreaded, and you probably don't need to use it (especially if the singleton itself isn't thread-safe).