2014-05-30 22:08:51 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
|
2012-08-30 21:02:30 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2015-12-01 03:43:03 +08:00
|
|
|
#include "test.h"
|
2012-08-30 21:02:30 +08:00
|
|
|
|
|
|
|
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);
|
2015-12-01 03:43:03 +08:00
|
|
|
print_address("addr=", 1, p);
|
2012-08-30 21:02:30 +08:00
|
|
|
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:
|
2014-05-30 22:08:51 +08:00
|
|
|
// CHCEK: #0 malloc
|
2013-01-30 16:41:57 +08:00
|
|
|
// CHECK: #{{1|2}} alloc
|
|
|
|
// CHECK: #{{2|3}} 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
|