This commit adds an interceptor for the pthread_detach function,
calling into ThreadRegistry::DetachThread, allowing for thread contexts
to be reused.
Without this change, programs may fail when they create more than 8K
threads.
Differential D88184
[lsan] Add interceptor for pthread_detach. charco on Sep 23 2020, 2:47 PM. Authored by
Details This commit adds an interceptor for the pthread_detach function, Without this change, programs may fail when they create more than 8K
Diff Detail
Event TimelineComment Actions LSan sets the thread registry's maximum number of threads to 8192 (static const uptr kMaxThreads = 1 << 13; in lsan_thread.cpp). This test exercises various ways threads can be created and then reaped, and it ensures each can successfully run for 10,000 thread create/reap cycles. Without the associated LSan fix, some of the paths end up failing due to hitting LSan's thread limit. @charco We should probably add a comment to kTestThreads explaining this. (I think it's out of scope for this CL, but it would also be nice if, for testing, we could bump down to thread registry limits. E.g., ASan also leaks threads, but it sets a *much* higher thread limit. So running this test long enough to demonstrate ASan's leaks takes a non-trivial amount of time.) Comment Actions I tested and it's now the slowest lsan test. // Test that threads are reused. // RUN: %clangxx_lsan %s -o %t -lpthread && %run %t #include <pthread.h> #include <stdlib.h> // Number of threads to create. This value is greater than kMaxThreads in // lsan_thread.cpp so that we can test that thread contexts are not being // reused. static const size_t kTestThreads = 10000; void *null_func(void *args) { return NULL; } void detach_exited(void) { for (size_t i = 0; i < kTestThreads; i++) { pthread_t thread; pthread_create(&thread, NULL, null_func, NULL); pthread_detach(thread); } } int main() { detach_exited(); return 0; }
|
this way easier to copy full command line from test output when it fails :)