I have two threads operating in my app.
- In the Main thread I update values of keys in entities or gets some rows from Core Data.
- In the background thread I download data from a server.
But some times during update/processing on core data on [managedObjectContext executeFetchRequest:request error:&error]
… I get:
#0 0x34507c5c in semaphore_wait_signal_trap ()
#1 0x34507f58 in semaphore_wait_signal ()
#2 0x364d573a in pthread_mutex_lock ()
#3 0x35c91a2e in -[_PFLock lock] ()
#4 0x35c91a12 in -[NSPersistentStoreCoordinator lock] ()
#5 0x35c919e8 in -[NSManagedObjectContext(_NSInternalAdditions) lockObjectStore] ()
#6 0x35c90676 in -[NSManagedObjectContext executeFetchRequest:error:] ()
How does the NSManagedObjectContext get locked? What can I do for this?
The lock is part of the normal operation and is not the source of your problem.
Most likely, you have a problem managing the context on the separate threads. Make sure you use a different context for each thread and make sure you don’t pass managed objects between the threads. Make sure you merge the contexts before trying to access changes made on one thread from another.