| 15 | unsigned int global_shared_data[NUM_THREADS]; |
| 16 | |
| 17 | void *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 | |
| 55 | pthread_t thread[NUM_THREADS]; |
| 56 |
nothing calls this directly
no test coverage detected