objective c - CoreData Multithreading Proper Store Deletion -


ok, here's situation:

i've got app requires user-account. while you're doing stuff writing new comments, creating new posts or reading thread, every call server runs on separate thread. more specifically: new thread created, makes call server, gets answer server , saves items answer core data store.

in order this, every thread creates own insertioncontext, share same storecoordinator.

but there's 1 problem: when logout account, have delete store, if logs in account, stuff other account isn't in coredatastorage anymore.

but in order delete store, have make sure there aren't background threads running anymore, because once try to save stuff, sure crash app, since store isn't valid anymore. clarify: these background threads nsoperations put in nsoperationqueue , executed there.

now coredata gives nsoperationqueue function called "cancelalloperations" according documentation, running operations aren't killed, send cancel message... how use cancel message o_o far i'm checking @ points whether thread canceled , if is, don't execute other stuff, if stuff like:

nserror *saveerror = nil; if(!self.iscanceled)   [insertioncontext save:&saveerror]; 

there still possibility thread being canceled between if-check , save.

so question: how handle properly? question of canceling thread?

i think should not cancel operations since not kill thread immediately. why don't manage operations being executed? way can postpone persistent store deletion until tasks complete (or delete if there no operations in progress).


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -