| 31 | } |
| 32 | |
| 33 | void *WaitingThread(void *arg) { |
| 34 | // Last waiting thread creates the waking thread - this simplifies mutual synchronization needs |
| 35 | if ((long)arg == NUM_THREADS-1) { |
| 36 | pthread_create(&wakingThread, 0, WakingThread, 0); |
| 37 | } |
| 38 | |
| 39 | // Each waiting thread waits until wake thread changes the value at the wait address |
| 40 | while (emscripten_atomic_load_u32(&futexVal) == 0) { |
| 41 | emscripten_futex_wait(&futexVal, 0, INFINITY); |
| 42 | } |
| 43 | |
| 44 | // Tally up the number of awoken threads - last one to wake up signals test success |
| 45 | uint32_t old = emscripten_atomic_add_u32(&numAwoken, 1); |
| 46 | if (old + 1 == NUM_THREADS) { |
| 47 | emscripten_force_exit(0); |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | int main() { |
| 54 | for (intptr_t i = 0; i < NUM_THREADS; ++i) { |
nothing calls this directly
no test coverage detected