在方法体上使用 @synchronized 指令
-(void)testSynchronizeMethod:(int)value
{
@synchronized(value)
{
int value1 = 100; //sample line 1
int value2 = 120; //sample line 2
[self calledMethod];
}
}
//case 1
-(void)calledMethod
{
NSLog(@"is @synchronized directive applied to this method");
NSLog(@"what happens if I enclose this method with @synchronized directive");
}
**or**
//case 2
-(void)calledMethod
{
@synchronized(value){
NSLog(@"is @synchronized directive applied to this method");
NSLog(@"what happens if I enclose this method with @synchronized directive");
}
}
问:案例 2 是否围绕 '-(void) calledMethod' 创建了两个互斥锁?
编辑当我使用这种互斥锁时,我在主线程上收到一个信号 SIGINT。如果有人可以建议我出了什么问题,我将附上屏幕截图?