Questions tagged «spurious-wakeup»

7
Java中是否会发生虚假唤醒?
看到各种与锁定相关的问题,并且(几乎)总是发现“由于虚假唤醒而引起的循环”术语1我想知道,有人经历过这种唤醒(例如,假设硬件/软件环境不错)吗? 我知道“虚假”一词没有明显的原因,但是发生此类事件的原因可能是什么? (1注意:我不是在问循环练习。) 编辑:一个帮助器问题(对于那些喜欢代码示例的人): 如果我有以下程序,并且运行它: public class Spurious { public static void main(String[] args) { Lock lock = new ReentrantLock(); Condition cond = lock.newCondition(); lock.lock(); try { try { cond.await(); System.out.println("Spurious wakeup!"); } catch (InterruptedException ex) { System.out.println("Just a regular interrupt."); } } finally { lock.unlock(); } } } 我该怎么做才能await将其虚假地唤醒,而无需永远等待随机事件?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.