Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lsan] Don't crash on ThreadRegistry::threads_ data race
Comment "No lock needed" in CurrentThreadContext was wrong. Concurent ThreadRegistry::CreateThread can resize and relocate ThreadRegistry::threads_ the same time CurrentThreadContext reads it. To mitigate lock cost we store ThreadContext* instead of tid in THREADLOCAL cache, we can tid from the ThreadContext*. Reviewed By: kstoimenov, MaskRay Differential Revision: https://reviews.llvm.org/D148281
- Loading branch information
1 parent
67fed13
commit 7760272
Showing
7 changed files
with
55 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Check that concurent CurrentThreadContext does not crash. | ||
// RUN: %clangxx_lsan -O3 -pthread %s -o %t && %run %t 100 | ||
|
||
// REQUIRES: lsan-standalone | ||
|
||
#include <pthread.h> | ||
#include <stdlib.h> | ||
#include <vector> | ||
|
||
#include <sanitizer/common_interface_defs.h> | ||
|
||
namespace __lsan { | ||
class ThreadContextLsanBase *GetCurrentThread(); | ||
} | ||
|
||
void *null_func(void *args) { | ||
for (int i = 0; i < 100000; ++i) | ||
__lsan::GetCurrentThread(); | ||
return nullptr; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
std::vector<pthread_t> threads; | ||
for (int i = 0; i < atoi(argv[1]); ++i) { | ||
threads.resize(10); | ||
for (auto &thread : threads) | ||
pthread_create(&thread, 0, null_func, NULL); | ||
|
||
for (auto &thread : threads) | ||
pthread_join(thread, nullptr); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters