Question: What a correct way of pthreads start-up? #21963
Replies: 3 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
The core issue here is that new workers (the things that host pthreads) can start running if the main browser thread yeilds to the event loop. Because your main function is blocking, if your main function on the main browser thread then it cannot create new workers. See https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread |
Beta Was this translation helpful? Give feedback.
-
Hi @sbc100, I've tried to run the tree start-up with |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I'm working on improving oneTBB to support Emscripten and specifically on this issue our users faced.
The issue is that threads (tbb-workers) would not arrive into parallel regions and then everything is executed serially.
Our thread launch/wake-up model is "binary tree" where main thread will launch/wake-up only 2 threads and this threads will propagate signal to their subsequent threads.
Let's consider this example. It contains two implementations:
#define SERIAL 1
should be used)Using
-sPROXY_TO_PTHREAD
both code paths work with no problem. The problem is that not all the user can use it without refactoring.So I tried to experiment without this flag. Seems
SERIAL
code path is always working and it doesn't matter will I call join immediately after thread creation or use busy wait with no yields (as presented in example).However, tree like approach hangs unless I add
std::this_thread::yield()
into busy wait.[1] As I understood it happens because the first two threads will synchronously wait for
main
thread to help them with thread creation which it will never do because it locked in busy loop.Now I'm trying to figure our what will be the best approach for thread creation with Emscripten.
So I have several questions:
-sPROXY_TO_PTHREAD
? Why tree-like approach is working with the flag? How does it helps for subsequent threads creation?main
thread participate in thread creation no matter what?Beta Was this translation helpful? Give feedback.
All reactions