0
私は1分に1回メソッドを実行するタイマーを持っています。 メソッドにはいくつかのコードがあり、NSThreadを呼び出します。 NSthreadはクリティカルセクションを持つ別のメソッドを呼び出します。@synchronized in objectictive-c
時にはクリティカルセクションの実行に1分以上かかります。そして、別のスレッドが待機するのではなく、コードを実行せずに関数を終了するように@synchronizedに達する場合に必要です。
現在、私はそれがうまく機能していないように見えるし、2つのスレッドがクリティカルセクションに入るようです。
コード:
BOOL isRunning;
- (void)mainFunction
{
isRunning = NO;
[NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(glichyFunc) userInfo:nil repeates:YES];
}
- (void)glichyFunc
{
a++;
b--;
[NSThread detachNewThreadSelector:@selector(doJob) toTarget:self withObject:nil];
}
- (void)doJob
{
if (isRunning)
return;
isRunning = YES;
@syncronized{
c = [globalObject calculate];
isRunning = NO;
}
}
tryLockがその仕事をしました。ありがとう。 – Misha