| 83 | pthread_t thread[NUM_THREADS]; |
| 84 | |
| 85 | void RunTest(int test) { |
| 86 | pthread_attr_t attr; |
| 87 | pthread_attr_init(&attr); |
| 88 | pthread_attr_setstacksize(&attr, 4*1024); |
| 89 | |
| 90 | emscripten_outf("Main thread has thread ID %p\n", pthread_self()); |
| 91 | assert(pthread_self() != 0); |
| 92 | |
| 93 | switch(test) { |
| 94 | case 2: memset(sharedData, 0xFF, sizeof(sharedData)); break; |
| 95 | case 5: memset(sharedData, 0x10, sizeof(sharedData)); break; |
| 96 | default: memset(sharedData, 0, sizeof(sharedData)); break; |
| 97 | } |
| 98 | |
| 99 | emscripten_outf("Main: Starting test %d", test); |
| 100 | |
| 101 | for (int i = 0; i < NUM_THREADS; ++i) { |
| 102 | t[i].op = test; |
| 103 | t[i].threadId = i; |
| 104 | int rc = pthread_create(&thread[i], &attr, ThreadMain, &t[i]); |
| 105 | assert(rc == 0); |
| 106 | } |
| 107 | |
| 108 | pthread_attr_destroy(&attr); |
| 109 | |
| 110 | for (int i = 0; i < NUM_THREADS; ++i) { |
| 111 | int status = 1; |
| 112 | int rc = pthread_join(thread[i], (void**)&status); |
| 113 | assert(rc == 0); |
| 114 | assert(status == 0); |
| 115 | } |
| 116 | |
| 117 | int val = sharedData[0]; |
| 118 | emscripten_outf("Main: Test %d finished. Result: %d", test, val); |
| 119 | if (test != 6) { |
| 120 | for (int i = 1; i < DATA_COUNT; ++i) { |
| 121 | assert(sharedData[i] == sharedData[0]); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | int main() { |
| 127 | globalDouble = 5.0; |
no test coverage detected