Home | History | Annotate | Download | only in output_tests
      1 #include <pthread.h>
      2 #include <stdlib.h>
      3 #include <stdio.h>
      4 
      5 void *Thread1(void *p) {
      6   *(int*)p = 42;
      7   return 0;
      8 }
      9 
     10 void *Thread2(void *p) {
     11   *(int*)p = 44;
     12   return 0;
     13 }
     14 
     15 void *alloc() {
     16   return malloc(99);
     17 }
     18 
     19 void *AllocThread(void* arg) {
     20   return alloc();
     21 }
     22 
     23 int main() {
     24   void *p = 0;
     25   pthread_t t[2];
     26   pthread_create(&t[0], 0, AllocThread, 0);
     27   pthread_join(t[0], &p);
     28   fprintf(stderr, "addr=%p\n", p);
     29   pthread_create(&t[0], 0, Thread1, (char*)p + 16);
     30   pthread_create(&t[1], 0, Thread2, (char*)p + 16);
     31   pthread_join(t[0], 0);
     32   pthread_join(t[1], 0);
     33   return 0;
     34 }
     35 
     36 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
     37 // CHECK: WARNING: ThreadSanitizer: data race
     38 // ...
     39 // CHECK:   Location is heap block of size 99 at [[ADDR]] allocated by thread 1:
     40 // CHCEKL     #0 malloc
     41 // CHECK:     #1 alloc
     42 // CHECK:     #2 AllocThread
     43 // ...
     44 // CHECK:   Thread 1 (finished) created at:
     45 // CHECK:     #0 pthread_create
     46 // CHECK:     #1 main
     47