1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include <pthread.h>
3#include <unistd.h>
4
5void *thread(void *arg) {
6 pthread_mutex_t m;
7 pthread_mutex_init(&m, 0);
8 pthread_mutex_lock(&m);
9 pthread_mutex_destroy(&m);
10 return 0;
11}
12
13int main() {
14 pthread_t th;
15 pthread_create(&th, 0, thread, 0);
16 pthread_join(th, 0);
17 return 0;
18}
19
20// CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
21// CHECK: #0 pthread_mutex_destroy
22// CHECK: #1 thread
23// CHECK: and:
24// CHECK: #0 pthread_mutex_lock
25// CHECK: #1 thread
26// CHECK: Mutex {{.*}} created at:
27// CHECK: #0 pthread_mutex_init
28// CHECK: #1 thread
29// CHECK: SUMMARY: ThreadSanitizer: destroy of a locked mutex {{.*}} in thread
30