开发者

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

开发者 https://www.devze.com 2022-12-29 17:54 出处:网络
i have two methods -(void) a { @synchronized(self) { // critical section 1 } } -(void) b { @synchronized(self) {

i have two methods

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

-(void) b {
   @synchronized(self) {
      // critica开发者_开发技巧l 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号