| 22 | } |
| 23 | |
| 24 | void RunTest(int test) { |
| 25 | int NUM_THREADS = std::thread::hardware_concurrency(); |
| 26 | assert(NUM_THREADS > 0); |
| 27 | |
| 28 | emscripten_outf("Main: Test %d starting, with num cores: %d", test, NUM_THREADS); |
| 29 | |
| 30 | struct Test t[NUM_THREADS]; |
| 31 | pthread_t thread[NUM_THREADS]; |
| 32 | |
| 33 | pthread_attr_t attr; |
| 34 | pthread_attr_init(&attr); |
| 35 | pthread_attr_setstacksize(&attr, 4*1024); |
| 36 | |
| 37 | emscripten_outf("Main thread has thread ID %ld", pthread_self()); |
| 38 | assert(pthread_self() != 0); |
| 39 | |
| 40 | emscripten_outf("Main: Starting test %d", test); |
| 41 | |
| 42 | for (int i = 0; i < NUM_THREADS; ++i) { |
| 43 | t[i].threadId = i; |
| 44 | int rc = pthread_create(&thread[i], &attr, ThreadMain, &t[i]); |
| 45 | assert(rc == 0); |
| 46 | } |
| 47 | |
| 48 | pthread_attr_destroy(&attr); |
| 49 | |
| 50 | for (int i = 0; i < NUM_THREADS; ++i) { |
| 51 | int status = 1; |
| 52 | int rc = pthread_join(thread[i], (void**)&status); |
| 53 | assert(rc == 0); |
| 54 | assert(status == 0); |
| 55 | } |
| 56 | |
| 57 | emscripten_outf("Main: Test %d finished", test); |
| 58 | } |
| 59 | |
| 60 | int main() { |
| 61 | // Do a bunch of joins, verifying the Worker pool works. |
no test coverage detected