c# - Is it good to test a condition then lock then re-test the condition -
possible duplicate:
double-checked locking in .net
edit: lots of edits clarify question not singleton
i find myself writing code this:
if(resourceondiskneedsupdating) { lock(lockobject) { if(resourceondiskneedsupdating) // has previous thread done this? updateresourceondisk(); } } return loadresourcefromdisk();
updateresource()
slow operation. pattern make sense?
there better alternatives?
this called "double-checked locking".
you need memory fence make correct.
Comments
Post a Comment