问题描述
我只是想知道我理解的东西在这里。如果我获得与 Monitor.Enter
锁或锁定
我需要调用脉冲
释放锁之前?
I just want to make sure I understand something here. If I obtain a lock with Monitor.Enter
or lock
do I need to call Pulse
before releasing the lock?
Monitor.Enter
Monitor.Pulse // Is that neccessary?
Monitor.Exit
我一直认为,导致一个 Monitor.Exit
调用将调用隐 Monitor.Pulse
。是实际上真的吗?
I was always led to believe that a Monitor.Exit
call would implicitly invoke Monitor.Pulse
. Is that actually true?
我不完全相信当你将使用脉冲
。这是什么原因造成的混乱。
I'm not exactly sure when would you would use Pulse
. That is what is causing confusion.
推荐答案
没有,你并不需要调用脉冲
...但它不会自动完成,当你退出,无论是。
No, you don't need to call Pulse
... but it won't be done automatically when you exit, either.
脉冲
和 PulseAll
一起使用时用等待
用于信令目的。
Pulse
and PulseAll
are used in conjunction with Wait
for signalling purposes.
请参阅了解更多详情这个页面(忽略死锁位,基本上是:)
See the second half of this page for more details (ignore the deadlocking bit, basically :)
这篇关于目的Monitor.Pulse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!