On Wed, 10 Jul 2024 23:09:05 GMT, Chris Plummer <cjplum...@openjdk.org> wrote:
>> Adding a `sleep()` between two statements does not scale when the test in >> question is under different loads or run with different options. All it will >> do >> is make a hang more rare (and frustrating to analyze). >> >> We do use short sleeps when we are in a while-loop checking on a condition >> of some sort that indicates that the "thing" for which we are waiting to >> happen >> has happened. > > I believe we've done quite a few short sleeps like this in the past. Scaling > is not really an issue. It should only require at most a few ms, even with > -Xcomp, so we wait 1000ms and then never have to think about the timing > again. This test is ugly. Sometimes you have to fight ugly with ugly. > mainThead is suspended and is holding a println related lock, and thread2 is > stuck on the 2nd log call in runt2 awaiting the same lock. The classic example of why suspension is fraught with peril - the target must be guaranteed not to be holding any resource needed by the suspender. I think removing the logging may be the best bet here - with comments in the code to ensure someone does not add it back. Or else use a more primitive (native?) mechanism to do the logging, not System.out.println(). ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20088#discussion_r1673290543