0

Is it considered bad practice for a worker thread to do something like:

lock(resource_a);
lock(resource_b);
release(resource_a);
release(resource_b);

And if so, why? I have always made it practice to release in the reverse-order they were acquired (hierarchically), like this:

lock(resource_a);
lock(resource_b);
release(resource_b);
release(resource_a);

But I can't put my finger on why I need to do this, and if this rule is even rational.

My specific context is using CRITICAL_SECTION objects in Windows, but the question applies to any resource synchronization.

tenfour
  • 36,141
  • 15
  • 83
  • 142

0 Answers0