Permalink
Browse files

Fix asm2wasm dead lock caused by empty modules.

This commit fixes an asm2wasm dead lock when asm2wasm is compiling an
empty module, i.e. a module without any functions.

Without this commit, worker threads are likely to leave `workerMain()`
and decrease `liveWorkers` early.  Consequently, `waitUntilAllReady()`
will never observe `liveWorkers == numWorkers`.
  • Loading branch information...
loganchien committed Aug 25, 2016
1 parent a08643d commit a008d4fd7af3b04a3d351a03d56df7c28998690e
View
@@ -86,7 +86,15 @@ class OptimizingIncrementalModuleBuilder {
public:
// numFunctions must be equal to the number of functions allocated, or higher. Knowing
// this bounds helps avoid locking.
OptimizingIncrementalModuleBuilder(Module* wasm, Index numFunctions) : wasm(wasm), numFunctions(numFunctions), nextFunction(0), finishing(false) {
OptimizingIncrementalModuleBuilder(Module* wasm, Index numFunctions)
: wasm(wasm), numFunctions(numFunctions), endMarker(nullptr), list(nullptr), nextFunction(0),
numWorkers(0), liveWorkers(0), activeWorkers(0), availableFuncs(0), finishedFuncs(0),
finishing(false) {
if (numFunctions == 0) {
// special case: no functions to be optimized. Don't create any threads.
return;
}
// prepare work list
endMarker = new Function();
list = new std::atomic<Function*>[numFunctions];
View
@@ -0,0 +1,4 @@
function EmptyModule() {
'use asm';
return {};
}
View
@@ -0,0 +1,4 @@
(module
(memory 256 256)
(export "memory" memory)
)
@@ -0,0 +1,4 @@
(module
(memory 256 256)
(export "memory" memory)
)
@@ -0,0 +1,4 @@
(module
(memory 256 256)
(export "memory" memory)
)
@@ -0,0 +1,4 @@
(module
(memory 256 256)
(export "memory" memory)
)

0 comments on commit a008d4f

Please sign in to comment.