-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deadlock checking screen DPI (with AWT) while inside GlimpsePainter.paint() #41
Comments
Maybe the GlimpseLayout lock could become a read/write lock? Hold the write lock only while doing re-layout, then downgrade to read lock during paint? (Assuming the event thread only needs a read lock.) That way you can implement paint (common case) without having to worry about the AWT lock. |
Well, I can't get it to happen again. Stack traces of the deadlocked threads during the original occurrence are here. In the tests I'm running now, the event thread does not hold the AWT lock while handling events. Also, event handling stacktraces are now starting at DefaultEDTUtil.java:326, where in the deadlock it was DefaultEDTUtil.java:349. I guess JOGL 2 has two different code paths for event dispatch ... and apparently one of them can end up owning the AWT lock. |
In the render thread:
Meanwhile, in the event thread:
So the event thread can indeed hold the AWT lock while event listeners run. But only while a new canvas is being created. |
Added WaitForVisibleDeadlockExample in wfv-deadlock branch. To summarize ... you can get deadlock if: you move your mouse in an existing glimpse-canvas while a new glimpse-canvas is becoming visible, and a painter simultaneously tries to acquire the AWT lock (e.g. by calling getScreenResolution). |
Changing the GlimpseLayout lock to a read/write lock would fix this specific deadlock, but would not make everything work in general -- any painter that uses its own lock during event handling and rendering would encounter this same problem. Current lock acquisition order goes ("AWT" = AWT lock, "Layout" = GlimpseLayout lock, "Painter" = hypothetical lock in a painter):
I see the following ways to avoid deadlock:
Not clear whether Solution 1 is possible. Solution 2 would be an onerous restriction. Solution 3 would make all canvases unresponsive while a new one was being added, and would mean that only one canvas could render at a time. |
Do you reproduce this deadlock with NewtCanvasAWT? |
Yes, reproducible with NewtCanvasAWT: https://gist.github.com/stacktracer/11266465 In that snippet, the NewtSwingGlimpseCanvas contains a NewtCanvasAWT. (The snippet depends on Glimpse 2.1.1 ... sorry it's not a more self-contained example.) Glimpse 2.1.1 depends on JOGL 2.1.3, but deadlock still occurs if I bump the JOGL dependency up to JOGL 2.1.5-01. Run that snippet, move your mouse around in the window, and it deadlocks consistently. |
Deadlock can occur if a method that grabs the AWT lock (e.g. java.awt.Toolkit.getScreenResolution()) is called from inside GlimpsePainter.paint().
Event thread:
Render thread:
This causes issues with SVG Salamander, because it checks screen DPI when loading an SVG.
The text was updated successfully, but these errors were encountered: