由于内存模型,我意识到在java中双重检查锁定存在缺陷,但通常与单例模式相关联并优化单例的创建。双重锁定 - 目标c
怎么样在这种情况下,在Objective-C:
我有一个布尔标志,以确定是否我的应用程序是流数据或没有。我有3种方法,startStreaming,stopStreaming,streamingDataReceived我使用保护他们从多个线程:
- (void) streamingDataReceived:(StreamingData *)streamingData {
if (self.isStreaming) {
@synchronized(self) {
if (self.isStreaming) {
- (void) stopStreaming {
if (self.isStreaming) {
@synchronized(self) {
if (self.isStreaming) {
- (void) startStreaming:(NSArray *)watchlistInstrumentData {
if (!self.isStreaming) {
@synchronized(self) {
if (!self.isStreaming) {
这是双重检查uneccessary? objective-c中的双重检查是否与java中的问题类似?这种模式有哪些替代方案(反模式)。
感谢
你能证明这个答案吗? – 2012-07-26 13:23:39
您可以扩展答案以添加替代方案的建议。例如,Objective-C中是否存在与“transient”或AtomicInteger /等同等的内容? – 2013-07-03 13:00:21