diff --git a/tests/pthread/test_pthread_busy_wait.cpp b/tests/pthread/test_pthread_busy_wait.cpp new file mode 100644 index 0000000000000..63ed149b1be1b --- /dev/null +++ b/tests/pthread/test_pthread_busy_wait.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +int main() { + std::atomic done(false); + + std::thread t([&]{ + printf("in thread\n"); + done = true; + }); + + while (!done) { + // TODO(sbc): this call should not be needed. + // See: https://github.com/emscripten-core/emscripten/issues/15868 + emscripten_main_thread_process_queued_calls(); + std::this_thread::yield(); + } + + t.join(); + printf("done\n"); + return 0; +} diff --git a/tests/pthread/test_pthread_busy_wait.out b/tests/pthread/test_pthread_busy_wait.out new file mode 100644 index 0000000000000..68d3f84b54621 --- /dev/null +++ b/tests/pthread/test_pthread_busy_wait.out @@ -0,0 +1,2 @@ +in thread +done diff --git a/tests/pthread/test_pthread_cxx_threads.cpp b/tests/pthread/test_pthread_cxx_threads.cpp index b4eb79623c673..98751e88e395a 100644 --- a/tests/pthread/test_pthread_cxx_threads.cpp +++ b/tests/pthread/test_pthread_cxx_threads.cpp @@ -1,6 +1,10 @@ #include int main() { - std::thread([]{}).join(); + std::thread t([]{ + printf("in thread\n"); + }); + t.join(); + printf("done\n"); return 0; } diff --git a/tests/pthread/test_pthread_cxx_threads.out b/tests/pthread/test_pthread_cxx_threads.out index e69de29bb2d1d..68d3f84b54621 100644 --- a/tests/pthread/test_pthread_cxx_threads.out +++ b/tests/pthread/test_pthread_cxx_threads.out @@ -0,0 +1,2 @@ +in thread +done diff --git a/tests/test_core.py b/tests/test_core.py index 3fd12308d4fa8..1b6329fc03b1a 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -8476,12 +8476,16 @@ def test_pthread_c11_threads(self): @node_pthreads def test_pthread_cxx_threads(self): - self.set_setting('PROXY_TO_PTHREAD') - self.clear_setting('ALLOW_MEMORY_GROWTH') - self.set_setting('INITIAL_MEMORY', '64Mb') + self.set_setting('PTHREAD_POOL_SIZE', 1) self.set_setting('EXIT_RUNTIME') self.do_run_in_out_file_test('pthread/test_pthread_cxx_threads.cpp') + @node_pthreads + def test_pthread_busy_wait(self): + self.set_setting('PTHREAD_POOL_SIZE', 1) + self.set_setting('EXIT_RUNTIME') + self.do_run_in_out_file_test('pthread/test_pthread_busy_wait.cpp') + @node_pthreads def test_pthread_create_pool(self): # with a pool, we can synchronously depend on workers being available