NSLock deadlock

Posted by twinkle on Stack Overflow See other posts from Stack Overflow or by twinkle
Published on 2010-03-18T14:07:39Z Indexed on 2010/03/18 14:11 UTC
Read the original article Hit count: 1178

Filed under:

I have an instance variable in class Foo

 @property (nonatomic, retain) NSLock *mLock;

initialized as:

 self.mLock=[NSLock new];

Foo also has

-(void)getLock {
    while (![self.mLock tryLock]) { 
    NSLog(@"Trying to lock... sleep(1)");
    sleep(1); 
    }  
    NSLog(@">>>>>>> Acquiring LOCK");
    [self.mLock lock];
    NSLog(@">>>>>>> LOCK acquired");
}

From another method in the Foo class, I call [Foo getLock]. This immediately results in a deadlock. Log below:

2010-03-18 07:06:01.660 test[9816:207] >>>>>>> Acquiring LOCK
2010-03-18 07:06:01.665 test[9816:207] *** -[NSLock lock]: deadlock (<NSLock: 0x3c0f820>     '(null)')
2010-03-18 07:06:01.666 test[9816:207] *** Break on _NSLockError() to debug.

Thanks!

© Stack Overflow or respective owner

Related posts about xcode