[llvm] 1b43650 - [Support] Fix data race with “safe libc++”
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 18:43:56 PST 2023
Author: Vitaly Buka
Date: 2023-02-21T18:43:37-08:00
New Revision: 1b43650c419fd7448af1a9a097e062d1f64ca485
URL: https://github.com/llvm/llvm-project/commit/1b43650c419fd7448af1a9a097e062d1f64ca485
DIFF: https://github.com/llvm/llvm-project/commit/1b43650c419fd7448af1a9a097e062d1f64ca485.diff
LOG: [Support] Fix data race with “safe libc++”
Otherwise NFC.
Added:
Modified:
llvm/lib/Support/Parallel.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/Parallel.cpp b/llvm/lib/Support/Parallel.cpp
index c256d256be4f..f762e7abc833 100644
--- a/llvm/lib/Support/Parallel.cpp
+++ b/llvm/lib/Support/Parallel.cpp
@@ -55,7 +55,10 @@ class ThreadPoolExecutor : public Executor {
Threads.reserve(ThreadCount);
Threads.resize(1);
std::lock_guard<std::mutex> Lock(Mutex);
- Threads[0] = std::thread([this, ThreadCount, S] {
+ // Use operator[] before creating the thread to avoid data race in .size()
+ // in “safe libc++” mode.
+ auto& Thread0 = Threads[0];
+ Thread0 = std::thread([this, ThreadCount, S] {
for (unsigned I = 1; I < ThreadCount; ++I) {
Threads.emplace_back([=] { work(S, I); });
if (Stop)
More information about the llvm-commits
mailing list