1 // Test that lsan handles tls correctly for many threads
2 // RUN: %clangxx_lsan %s -o %t
3 // RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=0" not %run %t 2>&1 | FileCheck %s
4 // RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=1" %run %t 2>&1
5 // RUN: %env_lsan_opts="" %run %t 2>&1
7 // Patch r303906 did not fix all the problems.
8 // UNSUPPORTED: arm-linux,armhf-linux
16 static const int NUM_THREADS
= 10;
18 pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
19 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
36 void *thread_start(void *arg
) {
39 pthread_mutex_lock(&mutex
);
41 pthread_mutex_unlock(&mutex
);
43 // don't exit, to intentionally leak tls data
49 pthread_t thread
[NUM_THREADS
];
50 for (int i
= 0; i
< NUM_THREADS
; ++i
) {
51 assert(0 == pthread_create(&thread
[i
], 0, thread_start
, 0));
53 // spin until all threads have finished
54 while (finished
< NUM_THREADS
)
59 // CHECK: LeakSanitizer: detected memory leaks
60 // CHECK: SUMMARY: {{.*}}Sanitizer: