2012-09-18 15:23:54 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
|
2012-08-30 21:02:30 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
void *Thread1(void *p) {
|
|
|
|
*(int*)p = 42;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Thread2(void *p) {
|
2012-08-31 16:00:37 +08:00
|
|
|
*(int*)p = 44;
|
2012-08-30 21:02:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *alloc() {
|
|
|
|
return malloc(99);
|
|
|
|
}
|
|
|
|
|
2012-08-31 16:00:37 +08:00
|
|
|
void *AllocThread(void* arg) {
|
2012-08-30 21:02:30 +08:00
|
|
|
return alloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
void *p = 0;
|
|
|
|
pthread_t t[2];
|
|
|
|
pthread_create(&t[0], 0, AllocThread, 0);
|
|
|
|
pthread_join(t[0], &p);
|
|
|
|
fprintf(stderr, "addr=%p\n", p);
|
|
|
|
pthread_create(&t[0], 0, Thread1, (char*)p + 16);
|
|
|
|
pthread_create(&t[1], 0, Thread2, (char*)p + 16);
|
|
|
|
pthread_join(t[0], 0);
|
|
|
|
pthread_join(t[1], 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
|
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
2012-08-31 16:00:37 +08:00
|
|
|
// ...
|
2012-12-06 20:16:15 +08:00
|
|
|
// CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread T1:
|
2012-09-01 01:27:49 +08:00
|
|
|
// CHCEKL #0 malloc
|
|
|
|
// CHECK: #1 alloc
|
|
|
|
// CHECK: #2 AllocThread
|
2012-08-31 16:00:37 +08:00
|
|
|
// ...
|
2012-12-18 00:28:15 +08:00
|
|
|
// CHECK: Thread T1 (tid={{.*}}, finished) created by main thread at:
|
2012-08-30 21:02:30 +08:00
|
|
|
// CHECK: #0 pthread_create
|
|
|
|
// CHECK: #1 main
|