2

I read code somewhere in which multiple identical synchronized blocks are used, like this:

@implementation Test {
  NSObject var;
}

- (void)method1 {
  @synchronized(self) {
    @synchronized(var) {
     ...
    }
  }
}

- (void)method2 {
  @synchronized(self) {
    @synchronized(var) {
     ...
    }
  }
}

What's the rationale behind doing nested synchronized of self and var this way? Isn't @synchronized on var alone enough?

Boon
  • 40,656
  • 60
  • 209
  • 315

0 Answers0