Skip to content

Fix ThreadPool stop flag data race in destructor#112

Open
Aristide021 wants to merge 1 commit intoml-explore:mainfrom
Aristide021:fix/threadpool-stop-race
Open

Fix ThreadPool stop flag data race in destructor#112
Aristide021 wants to merge 1 commit intoml-explore:mainfrom
Aristide021:fix/threadpool-stop-race

Conversation

@Aristide021
Copy link
Copy Markdown

Fixes a ThreadPool teardown data race on stop_threads_.

Workers read stop_threads_ under task_mutex_, but destructor wrote it without locking. That is an unsynchronized read/write (UB).
This PR writes stop_threads_ under task_mutex_ in ThreadPool.cpp (line 53), then notify_all() and join as before.

Validation:

Before fix: TSAN reports data race (ThreadPool.cpp:54, destructor write vs worker read).
After fix: same TSAN harness (5000 create/destroy loops) exits clean with no race report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant