An interesting article I found on the dangers of locking resources explained in a nice
real life example.
The main points:
"I explained to her that it’s an elementary principle of concurrent system design that you minimise your lock phases: acquire a resource, use it and release it as quickly as possible, so that the resource can be used by other agents...I explained as politely as I could that separation of concerns is one of the most fundamental of all the principles of system design, and that for me to reschedule my own tasks and take on other agents’ responsibilities would be a gross violation of encapsulation. I explained that, instead, when she accepted the get-the-boys’-drinks interrupt, she should have relinquished her lock and passed the cheese back down to my end of the table before going swanning off off on the drinks mission."
Full link: http://reprog.wordpress.com/2010/03/30/a-brief-yet-helpful-lesson-on-elementary-resource-locking-strategyAnd also a nice response found on
reddit =)
"Handling interrupts while locking resources is not just sub-optimal but it's highly dangerous. Imagine if both parents were so careless and, for example, when she handled the drinks-for-the-boys interrupt he was in the middle of geting himself something to drink. Further imagine that while having the drink source resource locked he handled an interrupt from the boys for some cheese on their food. BLAMMO! You're deadlocked! Everyone starves and you've got a dead family on your hands.
Not only is his strategy of releasing locks before handling interrupts speed efficient, it's also important for survival. They really dodged a bullet with that cheese thing. I can't believe his wife was so reckless with the safety of her entire family."