Does @synchronized(self) create a block where the self prefix is unecessary on properties?
Please read this Documentation
The
@synchronized()
directive locks a section of code for use by a single thread. Other threads are blocked until the thread exits the protected code—that is, when execution continues past the last statement in the@synchronized()
block.The
@synchronized()
directive takes as its only argument any Objective-C object, includingself
.
As Massimo Cafaro pointed out: "It’s safest to create all the mutual exclusion objects before the application becomes multithreaded, to avoid race conditions."
@synchronized(self) is used to get rid of the self. prefix.
So in my example I set the strText not in the function I set it in the class.
Two concepts are being conflated.
@synchronized(self) { ... }
only locks the block using theself
object as the semaphore.- In Objective-C, there is nothing like a hypothetical
with
statement as in other languages that removes the need forself.whatever
to be justwhatever
. Might want to take the Stanford CS193P online course to brush up on the language.