0

if (time != currentTime)デバッガーで停止して起動する次のコードがあります。それに関する情報が見つからず、例外をログに記録しようとしても機能しません。

- (void)viewWillAppear:(BOOL)animated {
    [self startIt];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self stopIt];
}

- (void)startIt {
    isRunning = YES;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        @try {
            NSTimeInterval time = currentTime;
            while (isRunning) {
                if (time != currentTime) {  // app stops here with EXC_??? (11)
                    time = currentTime;
                    // do other work
                }
            }
        }
        @catch (NSException *e) {
            NSLog(@"Exception %@", e);
        }
    });
}

// Delegate method called when broadcasting time
- (void)updateCurrentTime:(NSInteger)time {
    @synchronized(self) {
        currentTime = time;
    }
    [anotherView doStuffWIthTime:time];
}

- (void)stopIt {
    isRunning = NO;
}

スタック トレースを表示してもあまり役に立ちません。

* thread #6: tid = 0x2503, 0x0021e6e3 Project`__46-[MyViewControlleriPad startRunQueue]_block_invoke() + 131 at MyViewControlleriPad.m:343, stop reason = EXC_??? (11) (code=0, subcode=0x0)
    frame #0: 0x0021e6e3 Project`__46-[MyViewControlleriPad startRunQueue]_block_invoke() + 131 at MyViewControlleriPad.m:343
    frame #1: 0x03f1653f libdispatch.dylib`_dispatch_call_block_and_release + 15
    frame #2: 0x03f28014 libdispatch.dylib`_dispatch_client_callout + 14
    frame #3: 0x03f192e8 libdispatch.dylib`_dispatch_root_queue_drain + 335
    frame #4: 0x03f19450 libdispatch.dylib`_dispatch_worker_thread2 + 39
    frame #5: 0x96f33e72 libsystem_c.dylib`_pthread_wqthread + 441

編集:設定されていることを示すために更新されましたisRunning。アクセスを同期していないことに気付きました。それはこの問題を解決しますか?と思っていましたcurrentTime

4

0 に答える 0