objective-c : @synchronized, how does it work?

11,153

Critical section 2 will be blocked to other threads, as well, since you're synchronizing on the same object (self).

Share:
11,153
g.revolution
Author by

g.revolution

i m a geek :d SOreadytohelp

Updated on June 18, 2022

Comments

  • g.revolution
    g.revolution almost 2 years

    i have two methods

    -(void) a {
       @synchronized(self) {
          // critical section 1 
       }
    }
    
    -(void) b {
       @synchronized(self) {
          // critical section 2 
       }
    }
    

    now my question is if a thread is in critical section 1. will the critical section 2 be locked for other threads or other threads can access critical section 2.