In my experience it's easy to cause a deadlock if the main threaded spawns a thread then immediately waits on it.
Untested, but something simple like this will probably cause the browser to hang if compiled with PTHREAD_POOL_SIZE=0:
main() {
std::future<int> futureInt( std::async([&]{
return print("test");
}) );
int returnValue = futureInt.get();
}
This is because the browser has to create a worker on the main thread, but is waiting on the main thread inside the get().
I'm not the only one to run into this issue (eg: #8078). I'm sure there's many other hangs logged that are caused by the same issue.
I think the easiest fix would be a another flag to make PTHREAD_POOL_SIZE a hard limit, and trying to create more threads will fail. Maybe PTHREAD_CLAMP_POOL_SIZE?
If that's not acceptable, perhaps something could be exposed on the native side that returns the number of free workers. Something equivalent to:
int GetNumberOfAvailableWorkers() {
return EM_ASM_INT({
return PThread.unusedWorkerPool.length;
});
}
Anyone have any thoughts on this?
In my experience it's easy to cause a deadlock if the main threaded spawns a thread then immediately waits on it.
Untested, but something simple like this will probably cause the browser to hang if compiled with
PTHREAD_POOL_SIZE=0:This is because the browser has to create a worker on the main thread, but is waiting on the main thread inside the
get().I'm not the only one to run into this issue (eg: #8078). I'm sure there's many other hangs logged that are caused by the same issue.
I think the easiest fix would be a another flag to make
PTHREAD_POOL_SIZEa hard limit, and trying to create more threads will fail. MaybePTHREAD_CLAMP_POOL_SIZE?If that's not acceptable, perhaps something could be exposed on the native side that returns the number of free workers. Something equivalent to:
Anyone have any thoughts on this?