开发者

Returning from method inside a @synchronized block

I'd just like to know if it's advised to return from a method within a @synchronized block? For example:

- (id)test {
   @synchronized(self) {
      if (a) return @"A";
      else return @"B";
   }
}

As opposed to:

- (id)test {
   NSString *value;
   @synchronized(self) {
      if (a) 开发者_开发技巧value = @"A";
      else value = @"B";
   }
   return value;
}

This sample is rather simplistic, but sometimes in a complex method it would make things simpler to be able to return from within a @synchronized block.


It's fine. @synchronized is aware of the return statement.

(Ref: http://www.thaesofereode.info/clocFAQ/#sync-advs) - dead link
(Ref: http://nextstep.sdf-eu.org/clocFAQ/#sync-advs) - this link reference above dead one and may not be up to date as its header says

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜