0

I'm attempting to create a multithreaded transition animation system, but am confused by seemingly corrupted state in an NSCondition object I'm using for synchronization. I've added some lines from my debugger below to illustrate what's happening:

po [NSThread currentThread]
<NSThread: 0x146f77a0>{name = Transition Animation, num = 4}

po _condition
<NSCondition: 0x1464dff0>{locked = YES, thread = 0xb083b000, name = nil}

p *(NSCondition*)_condition
(NSCondition) $5 = {
  NSObject = {
    isa = NSCondition
  }
_priv = 0x00000000
}

What's confusing me is the address and name given by the condvar's description since they don't match up with the name and address of the NSThread that's calling -lock on the condition. Additionally, inspecting the actual contents of the NSCondition itself isn't helpful since its _priv pointer is nil. Does anyone have any experience with this or know how to fix it?

P.S. Before people suggest that I just use GCD for concurrency: I'm using CADisplayLinks for my animation, so I need to use NSThreads since CADisplayLinks require an NSRunLoop to trigger updates.

  • You need to add some code that shows how you are locking/signalling and unlocking the NSCondition and where the error occurs. The message suggests that a thread is exiting while still holding a lock – Paulw11 Jun 17 '14 at 02:14
  • There are two threads using this condvar: the main thread and the NSThread object that I create on which to run my CADisplayLink. Basically, I create an NSThread that loops until it's cancelled and waits on the condition variable if there aren't any transition animator objects created. The condition being waited for in the thread's loop is a property of my class is non-nil. In the setter for the property, I lock the condvar, reset the ivar backing the property, broadcast the condvar, then unlock. Both threads are persistent throughout the runtime of the app. – Kurt Horimoto Jun 18 '14 at 00:55
  • Moreover, I attempted to replace the NSCondition with a subclass and put a breakpoint in `-lock`, but it was never called by a thread with the address printed above. – Kurt Horimoto Jun 18 '14 at 15:57
  • Please show your code – Paulw11 Jun 18 '14 at 22:24

0 Answers0