Deadlock? (main thread keeps waiting)


#1

Hi everyone,

I’m pretty sure that my processing sketch deadlocks and I’m having trouble debugging it.

Most of the time, the sketch runs fine but once in a while - sometimes after 10 minutes, sometimes after 6 hours of runtime - the sketch comes to a halt and stops rendering. Seems like a classic deadlock.

Using the VisualVM debugger I’ve been able to debug the supposedly deadlocked program. I can see that most threads are in a waiting state, including (what I’m guessing to be) the main rendering thread main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1 which is waiting on a java.util.TaskQueue:

"main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1" Id=23 WAITING on java.util.TaskQueue@36fa2b88
	at java.lang.Object.wait(Native Method)
	-  waiting on java.util.TaskQueue@36fa2b88
	at java.lang.Object.wait(Object.java:502)
	at java.util.TimerThread.mainLoop(Timer.java:526)
	at java.util.TimerThread.run(Timer.java:505)

I’m using the processing video library (processing.video) as well as the Client class from processing.net package.

The movieEvent() and the clientEvent() methods of my sketch are being called regularly, even when the sketch seems to be deadlocked, and I am able to detect the deadlock from there (by checking how long it’s been since the last draw() was called).

I am also able to print a thread dump to my log file from either of those methods. I’ve been logging those thread dumps for a while and they always looks something like this:

"Thread-151270" Id=151815 RUNNABLE
	at sun.management.ThreadImpl.dumpThreads0(Native Method)
	at sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:454)
	at LANDSCAPE$DebugUtilities.getThreadDump(LANDSCAPE.java:1909)
	at LANDSCAPE.movieEvent(LANDSCAPE.java:458)
	at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at processing.video.Movie.fireMovieEvent(Unknown Source)
	...

"gstreamer service thread 1" Id=66 WAITING on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@73f8bb93
	at sun.misc.Unsafe.park(Native Method)
	-  waiting on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@73f8bb93
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
	at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1081)
	at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
	at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	...

"Thread-6" Id=25 RUNNABLE (in native)
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
	at java.net.SocketInputStream.read(SocketInputStream.java:171)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at processing.net.Client.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:748)

"main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1" Id=23 WAITING on java.util.TaskQueue@36fa2b88
	at java.lang.Object.wait(Native Method)
	-  waiting on java.util.TaskQueue@36fa2b88
	at java.lang.Object.wait(Object.java:502)
	at java.util.TimerThread.mainLoop(Timer.java:526)
	at java.util.TimerThread.run(Timer.java:505)

"DestroyJavaVM" Id=21 RUNNABLE

"main-Display-.macosx_nil-1-EDT-1" Id=18 TIMED_WAITING on java.util.ArrayList@4902727c
	at java.lang.Object.wait(Native Method)
	-  waiting on java.util.ArrayList@4902727c
	at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:355)

"Java2D Disposer" Id=13 WAITING on java.lang.ref.ReferenceQueue$Lock@7061856
	at java.lang.Object.wait(Native Method)
	-  waiting on java.lang.ref.ReferenceQueue$Lock@7061856
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
	at sun.java2d.Disposer.run(Disposer.java:148)
	at java.lang.Thread.run(Thread.java:748)

"Java2D Queue Flusher" Id=12 TIMED_WAITING on sun.java2d.opengl.OGLRenderQueue$QueueFlusher@31141f06
	at java.lang.Object.wait(Native Method)
	-  waiting on sun.java2d.opengl.OGLRenderQueue$QueueFlusher@31141f06
	at sun.java2d.opengl.OGLRenderQueue$QueueFlusher.run(OGLRenderQueue.java:203)

"AWT-AppKit" Id=10 RUNNABLE (in native)

"Signal Dispatcher" Id=4 RUNNABLE

"Finalizer" Id=3 WAITING on java.lang.ref.ReferenceQueue$Lock@56d5d4c7
	at java.lang.Object.wait(Native Method)
	-  waiting on java.lang.ref.ReferenceQueue$Lock@56d5d4c7
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
	at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)

"Reference Handler" Id=2 WAITING on java.lang.ref.Reference$Lock@c9eddf3
	at java.lang.Object.wait(Native Method)
	-  waiting on java.lang.ref.Reference$Lock@c9eddf3
	at java.lang.Object.wait(Object.java:502)
	at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
	at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)

I’m using processing 3.4 and java version 1.8.0_181. I’ve seen the issue on both Windows and macOS.

How should I go about solving this? I’m unsure where to continue digging now…

Sincerely,