mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Core Data multi-threading assertion #64
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ruslanskorb on GitHub (Jun 15, 2016).
Hi John,
I have noticed that if you add the argument
-com.apple.CoreData.ConcurrencyDebug 1to Arguments Passed On Launch and try to invoke the code I provided belowNSManagedObjectContextwill throw the exception+[NSManagedObjectContext __Multithreading_Violation_AllThatIsLeftToUsIsHonor__].Apparently, this is because you are creating an object directly in your own transaction queue, not using neither the
performBlockAndWait(_:)method nor theperformBlock(_:)method of the managed object context.To fix it you can update the
performAndWait()method ofSynchronousDataTransactionwith the following code:And
commit(_:),perform()andperformAndWait()methods ofAsynchronousDataTransactionwith the following code:@ruslanskorb commented on GitHub (Jun 15, 2016):
If I'm right about that I'll be happy to create a PR :-]
@JohnEstropia commented on GitHub (Jun 15, 2016):
This has been reported here and here.
As I mentioned in those threads, you don't need to turn the
com.apple.CoreData.ConcurrencyDebugargument on because CoreStore is strict with its own queueing mechanism.@ruslanskorb commented on GitHub (Jun 15, 2016):
@JohnEstropia Sorry that I did not look for it in the already closed tasks.
But can you please explain why you don't want to use
performBlock(_:)/performBlockAndWait(_:)in your ownperform()andperformAndWait()methods that will allow to turn thecom.apple.CoreData.ConcurrencyDebugargument on?As they say Better safe than sorry :-]
@JohnEstropia commented on GitHub (Jun 15, 2016):
CoreStore queues transactions serially, so it manages transactions through children contexts in such a way that they will never interleave (with the exception of
UnsafeDataTransactions).In effect, there really is no point in using
performBlock()because there is no other context to protect against. In fact, enclosingperformBlock()from within the transaction queue actually introduces opportunities to deadlock. The context will be bound within multiple queues, and any attempt to cross another queue (e.g. fetching objects, which taps the parent context and/or the persistent store) becomes a deadlock risk.@ruslanskorb commented on GitHub (Jun 15, 2016):
@JohnEstropia Thanks for the explanation and special thanks for the library! 👍
One thing I would like to suggest is to add a small note about
com.apple.CoreData.ConcurrencyDebugin the README.And the issue can be closed :-]
@JohnEstropia commented on GitHub (Jun 16, 2016):
You're right, this should be explained in the documentation. I'll try to print a warning log when
com.apple.CoreData.ConcurrencyDebugis turned on as well.Thanks for the feedback! Really appreciate it :)
@JohnEstropia commented on GitHub (Jun 16, 2016):
I'll add a note in the
Installationsection of CoreStore 2.0's README regardingcom.apple.CoreData.ConcurrencyDebug. (corestore2_develop branch)@ruslanskorb commented on GitHub (Jun 16, 2016):
@JohnEstropia 👍