views:

39

answers:

1

If I have two Synclocks

synclock a
  synclock b
  end synclock
end synclock

am I in danger of a deadlock if I never have

synclock b
  synclock a
  end synclock
end synclock

in my code, but I do synclock on a or b randomly?

+1  A: 

As long as you always lock a before b then you'll be okay.

Hans Passant
True, but what I'm wondering is, if a is always locked from function 1 and b is always locked from function 2 and the synclock a,b is in function 3 and each function is running on different thread, will I still be ok?
Hamm Tia
The hard-to-see case is code that only locks b, then goes off inside some deeply nested code that locks a.
Hans Passant