Skip to content

Commit

Permalink
fix(io): fix data race on Windows
Browse files Browse the repository at this point in the history
Background_Thread_Pipe_Writer's destructor has a data race. It writes to
the stop_ member variable without acquiring the lock, but the background
thread might be reading the variable concurrently (with the lock held).

Fix the data race by guarding access to stop_ with a lock.
  • Loading branch information
strager committed Mar 25, 2024
1 parent 68bd5cb commit a3e64dd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/quick-lint-js/io/pipe-writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ Background_Thread_Pipe_Writer::Background_Thread_Pipe_Writer(
}

Background_Thread_Pipe_Writer::~Background_Thread_Pipe_Writer() {
this->stop_ = true;
this->data_is_pending_.notify_one();
{
std::unique_lock<Mutex> lock(this->mutex_);
this->stop_ = true;
this->data_is_pending_.notify_one();
}
this->flushing_thread_.join();
}

Expand Down

0 comments on commit a3e64dd

Please sign in to comment.