My app has to do a lot of syncing between the cloud database and core data, and this occurs in various methods. I do this using simple background threads:
dispatch_queue_t backgroundThread = dispatch_queue_create("background thread", NULL);
dispatch_async(backgroundThread, ^{ ...
However, if I do stuff too rapidly in the app, different synchronization tasks can occur simultaneously, which can cause unintended results.
Thus, I want to perform all synchronization tasks serially on just one thread. Whenever I need to perform a synchronization task, I want to dispatch it to the dedicated thread, not to be executed until that thread completes all previously submitted tasks. How should I manage that? Specifically...
- How should I instantiate my background serial thread?
- Should I take steps to retain it for the life of the app, or--not sure whether this is an issue--let it be released when not in use and then recreate it?
- How do I refer to it/dispatch to it from various methods/objects?
I've not been able to find an answer directly addressing this situation. This one (Using a single shared background thread for iOS data processing?) came close, but shied away.
Thanks for your time.