objective c - When is it safe to use -[NSManagedObjectContext lock]? -


i know should abide coredata's thread confinement rules in general, ever safe use -[nsmanagedobjectcontext lock] , friends? know accessing nsmanagedobject property can trigger implicit nsmanagedobjectcontext fetch if nsmanagedobject has unloaded properties, assume have wrap nsmanagedobject property accesses around -[nsmanagedobjectcontext lock] , -[nsmanagedobjectcontext unlock]. thought gotcha. there others?

in comments of this answer, marcus zarra says i'm misinterpreting the documentation -\[nsmanagedobjectcontext lock\] , friends:

sending message managed object context helps framework understand scope of transaction in multi-threaded environment. preferable use nsmanagedobjectcontext’s implementation of nslocking instead using of separate mutex object.

also, above quote implies can use other locks guard nsmanagedobjectcontext. true?

i'm not worried parent/child contexts question.

in academic setting, can use locks? yes.

should ever use them in production code? no. why? because odds of getting right first time extra-ordinarily high. getting right in maintenance mode rapidly approaches zero.

using locks access core data asking trouble. when wrong lose/corrupt data. when right breaking thread confinement. lose/lose gamble nothing gain.

the worst part there virtually no way know if got "right" until or unless lose data. never worth risk.

i point this response ben should give nice history on subject.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -