But developers there said that it is wrong and cause a deadlock. Please, comment if it is so or not?
If you think that it is deadlock can you produce reasonable deadlock scenario? (please)
You also think that notify() can just send notification to 'wrong' thread. We have two kind of threads here: producers && consumers. If object can notify 'wrong' thread it means that there must be at least 2 different kind of threads in waiting pool, but it seems to me that it is impossible, because the thread here can go in waiting pool only if object is locked be the thread and while() condition matches. We have 2 opposite while() conditions here, when one true and thread going to waiting pool it means another condition is false and thread should be noticeable. Am I right?
Originally posted by Dmitry Popov:
Hello, Henry!
It seems to me, that deadlock is possible in my program and thank you for your sample. Couldn't we just use notifyAll() to solve the problem?
The deadlock happens when notification is send to 'wrong' thread. If we can move all kind of threads (i.e. notifyAll()) to 'ready-to-run' state then even if some of thema go to 'wait' then the others can solve the 'deadlock'.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi