Skip to content

Commit

Permalink
Fix: prevent writer threads from exceeding the maximum (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Aug 25, 2023
1 parent 76c9f63 commit b7e4bc2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/modules/candidateWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Module from './module.js';
* This class may be run concurrently with other classes.
*/
export default class CandidateWriter extends Module {
private static readonly THREAD_SEMAPHORE = new Semaphore(1);
private static readonly THREAD_SEMAPHORE = new Semaphore(Number.MAX_SAFE_INTEGER);

// WARN(cemmer): there is an undocumented semaphore max value that can be used, the full
// 4,700,372,992 bytes of a DVD+R will cause runExclusive() to never run or return.
Expand All @@ -37,7 +37,7 @@ export default class CandidateWriter extends Module {
this.options = options;

// This will be the same value globally, but we can't know the value at file import time
if (CandidateWriter.THREAD_SEMAPHORE.getValue() !== options.getWriterThreads()) {
if (options.getWriterThreads() < CandidateWriter.THREAD_SEMAPHORE.getValue()) {
CandidateWriter.THREAD_SEMAPHORE.setValue(options.getWriterThreads());
}
}
Expand Down

0 comments on commit b7e4bc2

Please sign in to comment.