且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

递归/嵌套锁定在C#中的lock语句

更新时间:2022-11-21 16:33:43

是的,基于锁的显示器在.NET中是递归的,并计数。

Yes, locks based on Monitor in .NET are recursive, and counted.

从文档的 Monitor.Enter

From the docs for Monitor.Enter:

这是法律对同一线程   则启动输入不止一次没有它   堵;然而,相等数量的   退出调用之前必须调用   等待在物体上的其他线程   将解除。

It is legal for the same thread to invoke Enter more than once without it blocking; however, an equal number of Exit calls must be invoked before other threads waiting on the object will unblock.

这是否是一件好事,或不为up辩论。

Whether this is a good thing or not is up for debate.