LINK:
http://www.danchisholm.net/july21/mybook/chapter17/exam2.html What are the possible results of attempting to compile and run the program?
a. All of the numbers 0 through 9 must always be printed
b. Some or all of the numbers 0 through 9 could be printed
c. Nothing is printed
d. Run-time error
Answers are b and c.
I checked the code and found that, sometimes I get no output, sometimes i get 012345 and sometimes 012345678. So answer seems to be right!
BUT ... My doubt is, notifyAll() when issued, will inform all of the waiting threads about the release of the lock on the object BUT ONLY ONE OF THOSE THREADS WILL BE GIVEN THE CHANCE. Am I right?
If I am right then, definitely ONLY ONE
THREAD WILL ACQUIRE THE LOCK now and that thread's name will be printed. Where come "no output" scenario and "0123456" (multiple thread's name) kind of scenario come into picture. Please elucidate! Thanks!
[ October 30, 2004: Message edited by: Barry Gaunt ]