Update DCTCoreDataStack.m - #5
Conversation
Fixes a crash on startup in situation when two threads (two MOCs) attempt to access PSC while it's still being created.
danielctull
commented
Sep 28, 2013
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
commented
Sep 29, 2013
I propose a simpler approach: Create the PSC (and likely main MOC too) in |
danielctull
commented
Sep 29, 2013
@mikeabdullah: Yup, completely agree. |
danielctull
commented
Sep 29, 2013
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
commented
Oct 12, 2013
Daniel, did you see the test fail when you created it before you fixed it? |
danielctull
commented
Oct 12, 2013
Yes. |
danielctull
commented
Oct 12, 2013
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. |
Fixes a crash on startup in situation when two threads (two MOCs) attempt to access PSC while it's still being created.