I was reading about Condition
objects and how they offer multiple wait-sets per object and also distinguishing which object or group of objects/threads get a specific signal.
Why doesn't a regular Object
do that? E.g.
Instead of:
final Condition notFull = lock.newCondition();
final Condition notEmpty = lock.newCondition();
lock.lock();
try {
while (count == items.length)
notFull.await();
items[putptr] = x;
if (++putptr == items.length) putptr = 0;
++count;
notEmpty.signal();
We do this:
final Object notFull = new Object();
final Object notEmpty = new Object();
lock.lock();
try {
while (count == items.length)
notFull.wait();
items[putptr] = x;
if (++putptr == items.length) putptr = 0;
++count;
notEmpty.notify();
Don't we still have multiple wait-sets and distinguish among notified threads?