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?

Hamm Tia
  • 11
  • 1

1 Answers1

3

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

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 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 Sep 07 '10 at 18:59
  • The hard-to-see case is code that only locks b, then goes off inside some deeply nested code that locks a. – Hans Passant Sep 07 '10 at 19:01