Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling saveContext() from any thread #59

Closed
markkrenek opened this issue Feb 19, 2016 · 3 comments
Closed

Calling saveContext() from any thread #59

markkrenek opened this issue Feb 19, 2016 · 3 comments
Labels
Milestone

Comments

@markkrenek
Copy link

Is saveContext() intended to be called from any thread? The docs say "This function is performed in a block on the context's queue" implying that I can call it from any thread. However, the first line (context.hasChanges) is not thread safe. I discovered this because I have com.apple.CoreData.ConcurrencyDebug enabled.

I know that I can wrap saveContext() inside a performBlock call to avoid this.

@markkrenek
Copy link
Author

Actually, if you enable com.apple.CoreData.ConcurrencyDebug in the example project, any save of a background context will trigger a concurrency crash, even though the initial call to saveContext() is wrapped in a performBlockAndWait.

saveContext() needs to delay checking hasChanges until inside performBlock.

@jessesquires
Copy link
Owner

Good catch @markkrenek ! 😄

Moving the hasChanges check sounds right. 👍

Want to submit a PR?

@jessesquires
Copy link
Owner

fixed by #65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants