NSLock - need to lock a lock lock?

I have a loop starting with

[lock lock]; 

because in the body of the loop I create another thread that needs to be finished before the loop starts again. (Another thread unlocks it when done).

However, in the second loop, I get the following error:

 2011-02-02 07:15:05.032 BLA[21915:a0f] *** -[NSLock lock]: deadlock (<NSLock: 0x100401f30> '(null)') 2011-02-02 07:15:05.032 BLA[21915:a0f] *** Break on _NSLockError() to debug. 

The "lock" documentation states the following:

Annotation. An attempt to obtain a lock by blocking the execution of threads until a lock is received. (Required)

what makes me think that it just blocks until a lock is received?

+8
cocoa nslock
source share
2 answers

It sounds like two problems:

  • Locking lock on one thread and unlocking on another is not supported - you probably want NSCondition . Wait for NSCondition in the parent thread and report it in the child thread.
  • Normal NSLock cannot be locked, although it is already locked. What is NSRecursiveLock ?
+8
source share

Did you remember to send -unlock when you're done? Each call to -lock must be paired with a call to -unlock .

+3
source share

All Articles