Returning from method inside a @synchronized block
Posted
by Michael Waterfall
on Stack Overflow
See other posts from Stack Overflow
or by Michael Waterfall
Published on 2010-04-24T12:13:13Z
Indexed on
2010/04/24
12:33 UTC
Read the original article
Hit count: 257
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.
© Stack Overflow or respective owner