Good work!
Thanks

Good to know that it runs with OpenJDK too.
I meanwhile found out why the volatile integer worked. The workerDone callback is synchronized altogether.
1 2 3 4 5 6 7 8 9
| public synchronized void workerDone() { int count = doneCount.incrementAndGet(); if(count == workers.size()) { notify(); } } |
Instead of doneCount.incrementAndGet() the r4 had a doneCount++ there. But since the whole method is synchronized, there was no race condition there, and it was sufficient to have the variable volatile, to make sure all cores have the same value.
Learned something again. I must say in all the years of using Java I didn't learn as much about concurrency than in this small project. It's been good to try
