2015-01-07 19:55:37 +00:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
|
2015-02-10 07:45:43 +00:00
|
|
|
#include "test.h"
|
2013-01-18 20:06:45 +00:00
|
|
|
|
|
|
|
int Global;
|
|
|
|
pthread_mutex_t mtx;
|
|
|
|
|
|
|
|
void *Thread1(void *x) {
|
|
|
|
pthread_mutex_lock(&mtx);
|
|
|
|
Global++;
|
|
|
|
pthread_mutex_unlock(&mtx);
|
2015-02-10 07:45:43 +00:00
|
|
|
barrier_wait(&barrier);
|
2013-01-18 20:06:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Thread2(void *x) {
|
2015-02-10 07:45:43 +00:00
|
|
|
barrier_wait(&barrier);
|
2013-01-18 20:06:45 +00:00
|
|
|
Global--;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-02-10 07:45:43 +00:00
|
|
|
barrier_init(&barrier, 2);
|
2013-01-18 20:06:45 +00:00
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
|
|
|
// CHECK: Write of size 4 at {{.*}} by thread T2:
|
|
|
|
// CHECK: Previous write of size 4 at {{.*}} by thread T1
|
|
|
|
// CHECK: (mutexes: write [[M1:M[0-9]+]]):
|
2015-01-07 19:55:37 +00:00
|
|
|
// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
|
2013-01-18 20:06:45 +00:00
|
|
|
// CHECK: #0 pthread_mutex_init
|
2015-12-30 11:52:19 +00:00
|
|
|
// CHECK: #1 main {{.*}}mutexset2.cc:[[@LINE+1]]
|
2013-01-18 20:06:45 +00:00
|
|
|
pthread_mutex_init(&mtx, 0);
|
|
|
|
pthread_t t[2];
|
|
|
|
pthread_create(&t[0], NULL, Thread1, NULL);
|
|
|
|
pthread_create(&t[1], NULL, Thread2, NULL);
|
|
|
|
pthread_join(t[0], NULL);
|
|
|
|
pthread_join(t[1], NULL);
|
|
|
|
pthread_mutex_destroy(&mtx);
|
|
|
|
}
|