-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
I have a repro here: https://gist.github.com/connorjclark/75c41ea6f3095b73dfb1815834e8761e – it is a test program that is composed of two worker threads, one produces jobs, the other consumes jobs. It uses a condition variable to orchestrate. The first file is implemented with pthread directly and works as expected on my mac and via emscripten. The second file uses equivalent SDL functions, and that works on my mac, but on the web via emscripten a deadlock occurs.
You'll notice some commented out lines of code–those are just slightly different ways to construct the locking, and they result in a deadlock too (but not on my mac).
I've upload the deadlocking example here: https://fallacious-bean.surge.sh/pthread.html
Note: surge.sh does not set the necessary headers for SAB, but you can use an extension like this to set Cross-Origin-Embedder-Policy=require-corp
and Cross-Origin-Opener-Policy=same-origin
(FWIW: refresh enough and you'll see 2 jobs processed before the deadlock)
The deadlock does not occur if SDL_CondWaitTimeout
(and its associated while loop) is not present (so the basic mutex lock/unlock work fine). Of course, the shared state is so trivial that concurrent reads/writes aren't noticeable–but this is because the example is purposefully simple.