Re: [问题] thread-safe queue

楼主: Yshuan (倚絃)   2019-04-26 12:20:16
que size已满. 三个Thread.
producer: Ta, Tb.
consumer: T1.
0. producer都先启动. 并且停在wait()
1. T1执行, 执行完后notify Ta.
2. Ta结束wait, 执行完后notify Tb
因为你的condition只有一个, 因此造成producer notify producer.
3. Tb结束wait. 执行并que overflow.
反之在que size已空, 2个getter先行并wait, 1个putter也有同样结果.
作者: adrianshum (Alien)   2019-04-26 21:44:00
用notifyAll 应该就行吧?虽然稍欠效率就是了

Links booklink

Contact Us: admin [ a t ] ucptt.com