ios - Is there a way to figure out what thread an NSManagedObjectContext is on? -
my understanding of threads respect nsmanagedobjectcontext
can execute core data fetch requests, deletes, etc., on thread created. there way check see thread nsmanagedobjectcontext
created on, or if @ particular point of execution current thread of particular nsmanagedobjectcontext
?
thanks!
my understanding of threads respect nsmanagedobjectcontext can execute core data fetch requests, deletes, etc., on thread created.
that's not accurate. better contexts cannot used concurrently more 1 thread or queue. common approach dealing create different contexts each thread/queue. it's possible use performblock
, performblockandwait
methods use contexts on multiple threads while keeping context access single-threaded.
as result, contexts don't have notion of belonging thread or queue, nor threads have reference contexts created on them.
if follow approach of 1 context per thread or queue, need keep track of code run , use appropriate context. example when using gcd, create context specific dispatch queue, , use when you've used dispatch_async
run on queue.
if want link context queue, use own data structure contexts whatever concurrency scheme you're using-- current nsoperationqueue
, or dispatch queue, or nsthread
, or whatever. needed, it's possibility if can't find better techniques.
Comments
Post a Comment