Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 2 | #include <pthread.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 5 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 6 | |
| 7 | void *Thread1(void *p) { |
| 8 | *(int*)p = 42; |
| 9 | return 0; |
| 10 | } |
| 11 | |
| 12 | void *Thread2(void *p) { |
| 13 | *(int*)p = 44; |
| 14 | return 0; |
| 15 | } |
| 16 | |
| 17 | void *alloc() { |
| 18 | return malloc(99); |
| 19 | } |
| 20 | |
| 21 | void *AllocThread(void* arg) { |
| 22 | return alloc(); |
| 23 | } |
| 24 | |
| 25 | int main() { |
| 26 | void *p = 0; |
| 27 | pthread_t t[2]; |
| 28 | pthread_create(&t[0], 0, AllocThread, 0); |
| 29 | pthread_join(t[0], &p); |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 30 | print_address("addr=", 1, p); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 31 | pthread_create(&t[0], 0, Thread1, (char*)p + 16); |
| 32 | pthread_create(&t[1], 0, Thread2, (char*)p + 16); |
| 33 | pthread_join(t[0], 0); |
| 34 | pthread_join(t[1], 0); |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | // CHECK: addr=[[ADDR:0x[0-9,a-f]+]] |
| 39 | // CHECK: WARNING: ThreadSanitizer: data race |
| 40 | // ... |
| 41 | // CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread T1: |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 42 | // CHCEK: #0 malloc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 43 | // CHECK: #{{1|2}} alloc |
| 44 | // CHECK: #{{2|3}} AllocThread |
| 45 | // ... |
| 46 | // CHECK: Thread T1 (tid={{.*}}, finished) created by main thread at: |
| 47 | // CHECK: #0 pthread_create |
| 48 | // CHECK: #1 main |