Skip to content

Commit

Permalink
Initialize workers in parallel.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-burlacu-software committed May 30, 2022
1 parent 65a7c19 commit 13cd6e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-fuzz",
"version": "5.0.1",
"version": "5.0.2",
"description": "Test case fuzzer with branch coverage guidance.",
"main": "./dist/src/fast-fuzz.js",
"types": "./dist/src/fast-fuzz.d.ts",
Expand Down
27 changes: 26 additions & 1 deletion src/fuzz/fuzzRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export class FuzzRunner {
this.pCount = pCount;
}

for (let index = 0; index < this.pCount; index++) {
// Bookkeeping.
const finalPromise = new FlatPromise();
let workersCount = 0;

// Inner function that initializes a worker
// and checks for the termination condition.
const initWorker = async () => {
const worker = new FuzzWorker();
this.workers.push(worker)
await worker.init(
Expand All @@ -46,7 +52,26 @@ export class FuzzRunner {
dist,
instances
);

await this.lock.acquireAsync();
try {
workersCount++;
} finally {
this.lock.release();
}

if (workersCount === this.pCount) {
finalPromise.resolve();
}
};

// Run the initialization function pCount times.
for (let index = 0; index < this.pCount; index++) {
initWorker();
}

// Wait until all the threads are initialized.
await finalPromise.promise;
}

/**
Expand Down

0 comments on commit 13cd6e1

Please sign in to comment.