从@synchronized块内的方法返回 [英] Returning from method inside a @synchronized block

查看:149
本文介绍了从@synchronized块内的方法返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否建议从 @synchronized 块中的方法返回?例如:

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";
   }
}

相反:

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

此示例相当简单,但有时候在一个复杂的方法中会产生一些东西更容易从 @synchronized 块中返回。

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.

推荐答案

没关系。 @synchronized 知道 return 语句。

(参考: http://www.thaesofereode.info/clocFAQ/#sync-建议 ) - 死链接

(参考: http://nextstep.sdf-eu.org/clocFAQ/#sync-advs ) - 此链接参考上面的死亡,可能不符合日期标题为

(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

这篇关于从@synchronized块内的方法返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆