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

Function ThreadMain

test/pthread/test_pthread_create.c:17–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15unsigned int global_shared_data[NUM_THREADS];
16
17void *ThreadMain(void *arg) {
18 long idx = (long)arg;
19 unsigned int param = global_shared_data[idx];
20
21#define N 100
22
23 emscripten_errf("Thread idx %lu: sorting %d numbers with param %d", idx, N, param);
24
25 unsigned int n[N];
26 // Create a shifted increasing sequence of numbers [0, N-1[
27 for (unsigned int i = 0; i < N; ++i) {
28 n[i] = (i + param) % N;
29 }
30
31 // Sort the sequence to ordered [0, N[
32 for (unsigned int i = 0; i < N; ++i) {
33 for (unsigned int j = i; j < N; ++j) {
34 if (n[i] > n[j]) {
35 unsigned int t = n[i];
36 n[i] = n[j];
37 n[j] = t;
38 }
39 }
40 }
41 // Ensure all elements are in place.
42 intptr_t numGood = 0;
43 for (unsigned int i = 0; i < N; ++i) {
44 if (n[i] == i) {
45 ++numGood;
46 } else {
47 emscripten_errf("n[%d]=%d", i, n[i]);
48 }
49 }
50
51 emscripten_outf("Thread idx %ld with param %d: all done with result %ld.", idx, param, numGood);
52 pthread_exit((void*)numGood);
53}
54
55pthread_t thread[NUM_THREADS];
56

Callers

nothing calls this directly

Calls 2

emscripten_errfFunction · 0.85
emscripten_outfFunction · 0.70

Tested by

no test coverage detected