Skip to content

Commit

Permalink
extras/threadedProcessing.ec: Fixed race condition
Browse files Browse the repository at this point in the history
- Fixed race condition on initial setup of processing stage thread
- Also some attempts at clarifying remaining potential race conditions upon stage termination
  • Loading branch information
jerstlouis committed Sep 12, 2023
1 parent 7e96c98 commit 038c620
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions extras/threadedProcessing.ec
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ProcessingStage
bool result = false;
ProcessingTask task;

mutex.Wait();
if(!thread)
{
thread = threads[0];
Expand All @@ -68,7 +69,6 @@ class ProcessingStage

// PrintLn("Thread ", thread.number, " working!");

mutex.Wait();
task = tasks.first;
if(task)
{
Expand Down Expand Up @@ -285,7 +285,10 @@ class ProcessingStage
{
semaphore.Release();
t.Wait();
delete threads[i];
mutex.Wait();
delete t;
threads[i] = null;
mutex.Release();
}
}
threads.size = 1;
Expand Down

0 comments on commit 038c620

Please sign in to comment.