Skip to content

Commit 4d4a353

Browse files
gbMattNvitalybuka
andauthored
[TSan] Increase the number of simultaneously locked mutexes that a thread can hold (#116409)
I've run into an issue where TSan can't be used on some code without turning off deadlock detection because a thread tries to hold too many mutexes. It would be preferable to be able to use deadlock detection as that is a major benefit of TSan. Its mentioned in google/sanitizers#950 that the 64 mutex limit was an arbitrary number. I've increased it to 128 and all the tests still pass. Considering the increasing number of cores on CPUs and how programs can now use more threads to take advantage of it, I think raising the limit to 128 would be some good future proofing --------- Co-authored-by: Vitaly Buka <[email protected]>
1 parent 5fa0345 commit 4d4a353

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class DeadlockDetectorTLS {
120120
u32 lock;
121121
u32 stk;
122122
};
123-
LockWithContext all_locks_with_contexts_[64];
123+
LockWithContext all_locks_with_contexts_[128];
124124
uptr n_all_locks_;
125125
};
126126

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -fsanitize=thread -o %t
2+
// RUN: %run %t 128
3+
4+
#include <mutex>
5+
#include <string>
6+
#include <vector>
7+
8+
int main(int argc, char *argv[]) {
9+
int num_of_mtx = std::atoi(argv[1]);
10+
11+
std::vector<std::mutex> mutexes(num_of_mtx);
12+
13+
for (auto &mu : mutexes) {
14+
mu.lock();
15+
}
16+
for (auto &mu : mutexes) {
17+
mu.unlock();
18+
}
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)