On Wed, 7 Oct 2020 23:35:00 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:
>> As far as I can see, the only effect `volatile` has here is making sure the >> successive calls to `checkEvent` eventually >> get the updated value of `discardingMouseEvents`. This does not seem to >> resolve the original race: calls to >> `checkEvent` can still see old values of `discardingMouseEvents` for a >> while, therefore some events can still leak. >> Turning the flag `volatile` makes it less likely, which might drop the error >> frequency under the testability threshold. >> Still, it might be good as the stop-gap. The iron-clad fix would be to >> synchronously insert something like >> `DiscardMouseEvent` on the beginning of event queue, and `AcceptMouseEvent` >> at the end of it, and let the `EventQueue` >> processor thread manage the flag -- so that `EventQueue` serializes >> everything, like it is designed to? > >> The iron-clad fix would be to synchronously insert something like >> `DiscardMouseEvent` on the beginning of event queue, >> and `AcceptMouseEvent` at the end of it, and let the `EventQueue` processor >> thread manage the flag -- so that >> `EventQueue` serializes everything, like it is designed to? > > Unfortunately, it is not possible to store this flag in EventQueue nor > EventDispatchThread and maintain it using > upcoming events, the JVM may run a few applications in parallel so it may > have more than one > EventQueue/EventDispatchThread and this code was written to discard all > events in all apps while one of them start > DnD. The code could be changed though when the support of multiple > EventQueue/EventDispatchThread will be finally > dropped. No problem. I was pointing out the `volatile` just makes us more lucky, does not fix the whole issue. Of course, it might be better than nothing. ------------- PR: https://git.openjdk.java.net/jdk/pull/491