Hi,

As Daniel said: "I think that what happens here is that the StdObservedObject.getNbObjects() getter unblocks the main thread before returning the value to the monitor. This makes it possible to have a race condition where the next setNbObjects called by the main thread can then occur before the result of StdObservedObject.getNbObjects() is taken into account - and even before the StdObservedObject.getNbObjects() actually returns. So StdObservedObject.getNbObjects() may return a value different than the one which was observed. In our case, it would return 3 (the newer value) instead of 0 (the value that was observed). "

The suggested fix is to return "observedValue" instead of "count", in this way we check also that the monitor never starts next observation before the current one finishes.

bug: https://bugs.openjdk.java.net/browse/JDK-8066952
webrev: http://cr.openjdk.java.net/~sjiang/JDK-8066952/00/

Thanks,
Shanliang

Reply via email to