RFR for JDK-8031374: java/util/concurrent/ConcurrentQueues/OfferRemoveLoops.java fails Intermittently
David Holmes
david.holmes at oracle.com
Sun Feb 23 22:59:21 UTC 2014
Hi Tristan,
I don't have time to analyse the original failure mode nor your proposed
changes but ...
On 23/02/2014 7:40 PM, Tristan Yan wrote:
> Hi All
> Could you please help to review fix for JDK-803174.
>
> http://cr.openjdk.java.net/~tyan/JDK-8031374/webrev.00/
>
> Description:
> There are a couple of code change for this code.
> 1. Original code has used known problematic Thread.stop. Which could cause ThreadDeath as all we know. I change it to a customized stopThread method.
> 2. Test failed in windows, I analyze the failure by changing Thread.yield() in remover thread to Thread.sleep(50). This is a simulation for slow machine. Which shows exact same failures as we can see in bug description. By adding more debug info, we can see although we tried to give up CPU by using Thread.yield().(I have tried to use Thread.sleep(1L) as well, the result is same), there is no guarantee that os will pick up a new thread to execute. In Windows, this is more obvious. Because the execution is slow. even when the timeout happens, offer thread and remove thread won’t have chance to get the point that i % 1024 == 0. This will cause the failure like we see in the log. My fix here is when the timeout happens, but i is still less than 1024. Stop offer thread and remover thread right away instead letting them continuously wait the point to i == 1024.
> 3. I replace Thread.yield to Thread.sleep(0L). I saw a couple of discussion that Thread.yield is not required to give up CPU.
Thread.sleep(0) has no meaningful semantics - it says "sleep for at
least zero time". That can be a no-op, or a yield-like operation or ...
An actual sleep of at least 10ms should be used, preferably a bit longer
as you don't know how the OS will behave if the sleep time requested is
less than the natural resolution of the sleep mechanism.
For Martin's benefit, while Thread.yield was always assumed to do the
right thing and act as reasonably expected, that got broken by the Linux
folks with CFS at one point. So loops involving yield are out of favour.
David
> Thank you
> Tristan
>
More information about the core-libs-dev
mailing list