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

前端 未结 3 770
温柔的废话
温柔的废话 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 11:52

    Locks in .NET are reentrant. Only acquisitions from other threads are blocked. When the same thread locks the same object multiple times, it simply increments a counter, and decrements it when released. When the counter hits zero, the lock is actually released for access from other threads.

提交回复
热议问题