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

Function RunTest

test/pthread/test_pthread_hardware_concurrency.cpp:24–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24void 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
60int main() {
61 // Do a bunch of joins, verifying the Worker pool works.

Callers 1

mainFunction · 0.70

Calls 6

hardware_concurrencyFunction · 0.85
pthread_attr_initFunction · 0.85
pthread_attr_destroyFunction · 0.85
emscripten_outfFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected