Skip to content

Commit 2ec15be

Browse files
authored
Thread fixes (#1205)
* don't use multiple threads in torture tests, which are parallel anyhow * if we fail to create a thread, don't use multiple threads
1 parent ee9d515 commit 2ec15be

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

check.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -471,31 +471,42 @@ def run_validator_tests():
471471
def run_torture_tests():
472472
print '\n[ checking torture testcases... ]\n'
473473

474-
unexpected_result_count = 0
474+
# torture tests are parallel anyhow, don't create multiple threads in each child
475+
old_cores = os.environ.get('BINARYEN_CORES')
476+
try:
477+
os.environ['BINARYEN_CORES'] = '1'
478+
479+
unexpected_result_count = 0
480+
481+
import test.waterfall.src.link_assembly_files as link_assembly_files
482+
s2wasm_torture_out = os.path.abspath(os.path.join(options.binaryen_test, 's2wasm-torture-out'))
483+
if os.path.isdir(s2wasm_torture_out):
484+
shutil.rmtree(s2wasm_torture_out)
485+
os.mkdir(s2wasm_torture_out)
486+
unexpected_result_count += link_assembly_files.run(
487+
linker=os.path.abspath(S2WASM_EXE),
488+
files=os.path.abspath(os.path.join(options.binaryen_test, 'torture-s', '*.s')),
489+
fails=os.path.abspath(os.path.join(options.binaryen_test, 's2wasm_known_gcc_test_failures.txt')),
490+
out=s2wasm_torture_out)
491+
assert os.path.isdir(s2wasm_torture_out), 'Expected output directory %s' % s2wasm_torture_out
492+
493+
import test.waterfall.src.execute_files as execute_files
494+
unexpected_result_count += execute_files.run(
495+
runner=os.path.abspath(WASM_SHELL_EXE),
496+
files=os.path.abspath(os.path.join(s2wasm_torture_out, '*.wast')),
497+
fails=os.path.abspath(os.path.join(options.binaryen_test, 's2wasm_known_binaryen_shell_test_failures.txt')),
498+
out='',
499+
wasmjs='')
475500

476-
import test.waterfall.src.link_assembly_files as link_assembly_files
477-
s2wasm_torture_out = os.path.abspath(os.path.join(options.binaryen_test, 's2wasm-torture-out'))
478-
if os.path.isdir(s2wasm_torture_out):
479501
shutil.rmtree(s2wasm_torture_out)
480-
os.mkdir(s2wasm_torture_out)
481-
unexpected_result_count += link_assembly_files.run(
482-
linker=os.path.abspath(S2WASM_EXE),
483-
files=os.path.abspath(os.path.join(options.binaryen_test, 'torture-s', '*.s')),
484-
fails=os.path.abspath(os.path.join(options.binaryen_test, 's2wasm_known_gcc_test_failures.txt')),
485-
out=s2wasm_torture_out)
486-
assert os.path.isdir(s2wasm_torture_out), 'Expected output directory %s' % s2wasm_torture_out
487-
488-
import test.waterfall.src.execute_files as execute_files
489-
unexpected_result_count += execute_files.run(
490-
runner=os.path.abspath(WASM_SHELL_EXE),
491-
files=os.path.abspath(os.path.join(s2wasm_torture_out, '*.wast')),
492-
fails=os.path.abspath(os.path.join(options.binaryen_test, 's2wasm_known_binaryen_shell_test_failures.txt')),
493-
out='',
494-
wasmjs='')
495-
496-
shutil.rmtree(s2wasm_torture_out)
497-
if unexpected_result_count:
498-
fail('%s failures' % unexpected_result_count, '0 failures')
502+
if unexpected_result_count:
503+
fail('%s failures' % unexpected_result_count, '0 failures')
504+
505+
finally:
506+
if old_cores:
507+
os.environ['BINARYEN_CORES'] = old_cores
508+
else:
509+
del os.environ['BINARYEN_CORES']
499510

500511
def run_vanilla_tests():
501512
print '\n[ checking emcc WASM_BACKEND testcases...]\n'

src/support/threads.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,14 @@ void ThreadPool::initialize(size_t num) {
111111
ready.store(threads.size()); // initial state before first resetThreadsAreReady()
112112
resetThreadsAreReady();
113113
for (size_t i = 0; i < num; i++) {
114-
threads.emplace_back(make_unique<Thread>());
114+
try {
115+
threads.emplace_back(make_unique<Thread>());
116+
} catch (std::system_error&) {
117+
// failed to create a thread - don't use multithreading, as if num cores == 1
118+
DEBUG_POOL("could not create thread\n");
119+
threads.clear();
120+
return;
121+
}
115122
}
116123
DEBUG_POOL("initialize() waiting\n");
117124
condition.wait(lock, [this]() { return areThreadsReady(); });

0 commit comments

Comments
 (0)