max_ max_ - 2 months ago 14
iOS Question

What does @synchronized() do?

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

@synchronized()
does, as I use it frequently, but do not know the meaning.

Answer

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).

Comments