Skip to content
This repository was archived by the owner on May 8, 2020. It is now read-only.

Conversation

@radianttap
Copy link

Fixes a crash on startup in situation when two threads (two MOCs) attempt to access PSC while it's still being created.

Fixes a crash on startup in situation when two threads (two MOCs) attempt to access PSC while it's still being created.
@danielctull
Copy link
Owner

Thanks for the pull request. I can see the issue is to do with accessing the managedObjectContext property from multiple threads at the same time. I've never come across this, I presume this is due accessing DCTCoreDataStack from the main thread.

I have added a unit test (although a poor one I admit) and fix on the threading branch. You can see my solution uses a private queue, which I think would be preferable going forward as we might want to use it for synchronising other parts of the setup. Could you check to see whether this solution resolves your issue?

Thanks again, Daniel

@mikeabdullah
Copy link
Contributor

I propose a simpler approach: Create the PSC (and likely main MOC too) in -init…. This removes the need for any locking/scheduling in the getter methods.

@danielctull
Copy link
Owner

@mikeabdullah: Yup, completely agree.

@danielctull
Copy link
Owner

Except, I've just realised that DCTCoreDataStack allows you to set an error handler for the loading, which won't be set until after init is returned. :-/ So it seems the queue is needed.

@Abizern
Copy link
Contributor

Abizern commented Oct 12, 2013

Daniel, did you see the test fail when you created it before you fixed it?

@danielctull
Copy link
Owner

Yes.

@danielctull
Copy link
Owner

As I explained in the commit message 894af35, it doesn't always fail, but because it's a race condition, I'm not sure there is a valid test for it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants