CountDownLatch是否受到虚假唤醒的影响? [英] Is CountDownLatch affected by spurious wakeups?
问题描述
诸如等待/通知和锁定/条件之类的并发管理机制似乎受到虚假唤醒的影响.开发人员通过重新检查条件确实已发生变化来迎合那些意外的唤醒.
Concurrency management mechanisms such as wait/notify and lock/condition seem to be affected by spurious wakeups. Developers cater for those unexpected wakeups by re-checking that the condition has indeed changed.
当涉及到CountDownLatch时,虚假唤醒是否是一个问题?
When it comes to CountDownLatch, are spurious wakeups an issue?
推荐答案
如果当前计数大于零,则当前线程
出于线程调度目的而被禁用,并且处于休眠状态,直到
发生两件事之一:
If the current count is greater than zero then the current thread
becomes disabled for thread scheduling purposes and lies dormant until
one of two things happen: 休眠表示该方法不会返回.换句话说,尽管会发生虚假的唤醒,但这不会导致 dormant meaning the method won't return. In other words, though a spurious wakeup can occur, it won't cause the 您可以查看LockSuport#park或 You can look at the implementation to see how this is done exactly, but, in brief, it's the typical trick of looping and "waiting" (through 当涉及到 When it comes to 否. 这篇关于CountDownLatch是否受到虚假唤醒的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
countDown()
方法而使计数达到零;或
countDown()
method; orawait
方法返回. await
method to return. Object#wait
受伪造唤醒的影响),直到满足条件为止.LockSuport#park
or Object#wait
which are affected by spurious wakeups) until a condition is met.
CountDownLatch
时,虚假唤醒是否是一个问题?
CountDownLatch
, are spurious wakeups an issue?