I had the same problem (lock on psynch_cvwait) when I changed context changes (in both directions) between the main and background context (both using NSConfinementConcurrencyType ). The problem was caused by subscribing to NSManagedObjectContextDidSaveNotification in another queue from which it was sent:
[[NSNotificationCenter defaultCenter] addObserverForName:NSManagedObjectContextDidSaveNotification object:mainContext queue:bgQueue usingBlock:^(NSNotification * _Nonnull note) {
As a result, the block was never called, and both main and background queues hung on psynch_cvwait()
I fixed it without blocking the mainContext queue:
[[NSNotificationCenter defaultCenter] addObserverForName:NSManagedObjectContextDidSaveNotification object:mainContext queue:nil usingBlock:^(NSNotification * _Nonnull note) { [bgQueue addOperationWithBlock:^{ [bgContext mergeChangesFromContextDidSaveNotification:note]; }]; }]
However, this does not seem to be a problem if I block the background queue when merging changes into the main context.
source share