Possible Duplicate:
objective-c : @synchronized, how does it work?
when i have three methods:
-(void) a {
@synchronized(self) {
//part a
}
}
-(void) b {
@synchronized(self) {
//part b
}
-(void) c {
// part c
}
and thread is in part a , then will be part c blocked for other threads?
Only
@synchronizedblocks interact with each other. As long as one thread is executing either partAor partB, no other thread can enter partAor partB. PartCis not affected by this in any way.Your new comment above made a bit clearer, what you are actually asking.
In
@synchronized(self),selfis not the thing that is locked itself, it is used as a lock to guarantee that only one thread at a time can enter the@synchronizedblock.As the official documentation explains: you can use any object as a semaphore.
The chapter on synchronization has a comprehensive description of all available locking options, btw.