I'd just like to know if it's advised to return
from a method within a @synchronized
block? For example:
我想知道是否建议从@synchronized块中的方法返回?例如:
- (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.
此示例相当简单,但有时在复杂的方法中,它可以使从@synchronized块中返回的内容变得更简单。
1 个解决方案
#1
11
It's fine. @synchronized
is aware of the return
statement.
没关系。 @synchronized知道return语句。
(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
(参考:http://www.thaesofereode.info/clocFAQ/#sync-advs) - 死链接(参考:http://nextstep.sdf-eu.org/clocFAQ/#sync-advs) - 此链接参考上面它的标题是死的,可能不是最新的
#1
11
It's fine. @synchronized
is aware of the return
statement.
没关系。 @synchronized知道return语句。
(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
(参考:http://www.thaesofereode.info/clocFAQ/#sync-advs) - 死链接(参考:http://nextstep.sdf-eu.org/clocFAQ/#sync-advs) - 此链接参考上面它的标题是死的,可能不是最新的