Skip to content

Commit e2cf42e

Browse files
authored
Fix for starting pthreads when -sENVIRONMENT=worker (#21993)
Fixes: #21989
1 parent 995df59 commit e2cf42e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/library_pthread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ var LibraryPThread = {
429429
// a pthread.
430430
'workerData': 'em-pthread',
431431
#endif
432-
#if ENVIRONMENT_MAY_BE_WEB
432+
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
433433
// This is the way that we signal to the Web Worker that it is hosting
434434
// a pthread.
435435
'name': 'em-pthread',

test/test_browser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4868,11 +4868,15 @@ def test_single_file_worker_js(self):
48684868

48694869
# Tests that pthreads code works as intended in a Worker. That is, a pthreads-using
48704870
# program can run either on the main thread (normal tests) or when we start it in
4871-
# a Worker in this test (in that case, both the main application thread and the worker threads
4872-
# are all inside Web Workers).
4873-
def test_pthreads_started_in_worker(self):
4871+
# a Worker in this test (in that case, both the main application thread and the worker
4872+
# threads are all inside Web Workers).
4873+
@parameterized({
4874+
'': ([],),
4875+
'limited_env': (['-sENVIRONMENT=worker'],),
4876+
})
4877+
def test_pthreads_started_in_worker(self, args):
48744878
self.set_setting('EXIT_RUNTIME')
4875-
self.compile_btest('pthread/test_pthread_atomics.cpp', ['-o', 'test.js', '-pthread', '-sPTHREAD_POOL_SIZE=8'], reporting=Reporting.JS_ONLY)
4879+
self.compile_btest('pthread/test_pthread_atomics.cpp', ['-o', 'test.js', '-pthread', '-sPTHREAD_POOL_SIZE=8'] + args, reporting=Reporting.JS_ONLY)
48764880
create_file('test.html', '''
48774881
<script>
48784882
new Worker('test.js');

0 commit comments

Comments
 (0)