-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[Bug] Deadlock w/ Timer
and Lwjgl3Application
#7548
Comments
One possible solution is to just make Edit: Actually, I am not sure why Timer tries to look at gdx.files in the first place. Can it simply not do that? (edit again: Ah, because it wants to be compatible with the lifecycle events and uses the files as a proxy for that.) |
Timer
and Lwjgl3Application.java
Timer
and Lwjgl3Application
I don't do much threading after a months-long bad experience, but I provide you with this link https://libgdx.com/wiki/app/threading#which-libgdx-classes-are-thread-safe and its relevant contents below:
I'm not sure how many more places other than the wiki need this disclaimer put in, prominently; I couldn't find it in the sources. I was also under the impression that any static state, anywhere in Java, is inherently unsafe to mutate on multiple threads simultaneously. I'm not sure if there's a way to do whatever you're doing in a thread-safe way. |
Yes I am familiar with that link. The If we want to say it is not thread safe, the implementation could be a lot simpler (just store tasks on the main thread, count down the time until they are ready). The documentation should also be updated to not imply it works across threads - it really seems like it is trying to be thread safe... (For my personal project, I have already replaced |
I agree |
Timer is indeed intended to be thread safe. Repro code wasn't provided, so I have to guess at it from the description. Maybe:
I doubt this is really a sensible thing to do, but here we goooo. The first app locks If my repro is wrong then we need an executable repro (like we always do). Related, I see unscynchronized read and write of libgdx/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3Application.java Lines 212 to 217 in 90b35b8
To be thread safe, all read and write access needs to be synchronized. |
Issue details
The situation is as follows:
Timer
, which causes the timer instance to be set and the gdx files instance to be cached.Timer
implies it supports this by checking if it's local version offiles
matches that of the staticGdx.files
, which will be important later).Now, the deadlock can happen like so:
synchronized
onlifecycleListeners
. This calls render().threadLock
in the instance() call, and so that lock is now held. When it calls the staticthread()
method, because GDX files has changed, it calls dispose(). While in dispose(), it tries to callremoveLifecycleListener
on Lwjgl3Application. We need thelifecycleListeners
lock to do so, but that is held by Main Thread. So we wait.threadLock
lock, which is held by Thread 2.Now, each thread is waiting for a lock that the other holds, and is deadlocked.
I was able to get this deadlock to happen in the intellij debugger and used a thread dump to confirm all of this.
Version of libGDX and/or relevant dependencies
1.13.0
Stacktrace
Thread 2:
Thread 1:
Please select the affected platforms
The text was updated successfully, but these errors were encountered: