Lock aqcuired and further attempts to lock do not block: are C# locks re-entrant?

前端 未结 3 768
温柔的废话
温柔的废话 2020-12-20 11:07

I\'ve written a test of what I think should be a valid case for a deadlock. It appears that once the lock has been acquired by an instance of the a class, that

3条回答
  •  天涯浪人
    2020-12-20 12:00

    In your scenario, you have a lock within another lock. Once the code hits the nested lock in "Deadlock", the "lock(...)" code is essentially ignored because it has already acquired it in "TestLock".

    Great source for threading: http://www.albahari.com/threading/part2.aspx.

提交回复
热议问题