MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / ThreadMain

Function ThreadMain

test/pthread/test_pthread_gcc_spinlock.c:17–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15volatile int lock = 0; // spinlock "mutex" variable
16
17void *ThreadMain(void *arg) {
18 printf("Thread started.\n");
19 for (int i = 0; i < 100; ++i) {
20#ifdef USE_EMSCRIPTEN_INTRINSICS
21 while(emscripten_atomic_exchange_u32((void*)&lock, 1))
22#else
23 while(__sync_lock_test_and_set(&lock, 1))
24#endif
25 {
26 /*nop*/;
27 }
28 int c = counter;
29 usleep(5 * 1000); // Create contention on the lock.
30 ++c;
31 counter = c;
32#ifdef USE_EMSCRIPTEN_INTRINSICS
33 emscripten_atomic_store_u32((void*)&lock, 0);
34#else
35 __sync_lock_release(&lock);
36#endif
37 }
38 printf("Thread done.\n");
39 pthread_exit(0);
40}
41
42#define NUM_THREADS 8
43

Callers

nothing calls this directly

Calls 4

printfFunction · 0.85
usleepFunction · 0.85

Tested by

no test coverage detected