这是示例代码的链接http://developer.apple.com/library/ios/#samplecode/MVCNetworking/Introduction/Intro.html
下面是文件NetworkManager.m中的代码片段
+ (NetworkManager *)sharedManager
// See comment in header.
{
static NetworkManager * sNetworkManager;
// This can be called on any thread, so we synchronise. We only do this in
// the sNetworkManager case because, once sNetworkManager goes non-nil, it can
// never go nil again.
if (sNetworkManager == nil) {
@synchronized (self) {
sNetworkManager = [[NetworkManager alloc] init];
assert(sNetworkManager != nil);
}
}
return sNetworkManager;
}
显然这里存在线程安全问题。当有多个线程时,可能会创建两个 NetworkManager 实例。所以苹果犯了一个错误,对吧?