Core data multithreading violation on transaction.create() #49

Closed
opened 2025-12-29 15:23:06 +01:00 by adam · 1 comment
Owner

Originally created by @Conrad-m-wise on GitHub (Apr 14, 2016).

I have this launch option set for my development scheme "-com.apple.CoreData.ConcurrencyDebug 1" to catch core data multi threading violations.

I am trying to create an object from a beginAsynchronous block but the app crashes

dataStack.beginAsynchronous { (transaction) in

        Delete any saved message with same id
        let int = transaction.deleteAll(From(ManagedUserMessage), Where("messageID", isEqualTo:message.messageID))

        if int > 0{
            log.debug("Did delete user message with ID:\(message.messageID)")
        }

        //Create new message
        let managedMessage = transaction.create(Into(ManagedUserMessage)) 

}

if i remove the launch option it does not fail.

Originally created by @Conrad-m-wise on GitHub (Apr 14, 2016). I have this launch option set for my development scheme "-com.apple.CoreData.ConcurrencyDebug 1" to catch core data multi threading violations. I am trying to create an object from a beginAsynchronous block but the app crashes dataStack.beginAsynchronous { (transaction) in ``` Delete any saved message with same id let int = transaction.deleteAll(From(ManagedUserMessage), Where("messageID", isEqualTo:message.messageID)) if int > 0{ log.debug("Did delete user message with ID:\(message.messageID)") } //Create new message let managedMessage = transaction.create(Into(ManagedUserMessage)) ``` } if i remove the launch option it does not fail.
adam added the wontfix label 2025-12-29 15:23:06 +01:00
adam closed this issue 2025-12-29 15:23:06 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Apr 14, 2016):

@Conrad-m-wise Hi, this is a duplicate of https://github.com/JohnEstropia/CoreStore/issues/28.

As I mentioned on that thread,

The com.apple.CoreData.ConcurrencyDebug flag lets Core Data tell you when the managed context is accessed from any queue other than its own, which includes CoreStore's transactions' queues (beginAsynchronous(), etc).

CoreStore already guarantees safety for you by making the Main Context read-only, and by only allowing updates to be made within transactions. You should be safe even without the ConcurrencyDebug flag (as long as you don't do hacky things).

Let me know if you need any clarifications :)

@JohnEstropia commented on GitHub (Apr 14, 2016): @Conrad-m-wise Hi, this is a duplicate of https://github.com/JohnEstropia/CoreStore/issues/28. As I mentioned on that thread, > The `com.apple.CoreData.ConcurrencyDebug` flag lets Core Data tell you when the managed context is accessed from any queue other than its own, which includes CoreStore's transactions' queues (`beginAsynchronous()`, etc). > > CoreStore already guarantees safety for you by making the Main Context read-only, and by only allowing updates to be made within transactions. You should be safe even without the ConcurrencyDebug flag (as long as you don't do hacky things). Let me know if you need any clarifications :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#49