Home | History | Annotate | Download | only in tests
      1 #include <pthread.h>
      2 #include <stdlib.h>
      3 #include <stdio.h>
      4 
      5 const int N = 1000;
      6 void *x[N];
      7 
      8 void *Thread1(void *unused) {
      9   for (int i = 0; i < N; i++) {
     10     fprintf(stderr, "%s %d\n", __func__, i);
     11     free(x[i]);
     12   }
     13   return NULL;
     14 }
     15 
     16 void *Thread2(void *unused) {
     17   for (int i = 0; i < N; i++) {
     18     fprintf(stderr, "%s %d\n", __func__, i);
     19     free(x[i]);
     20   }
     21   return NULL;
     22 }
     23 
     24 int main() {
     25   for (int i = 0; i < N; i++)
     26     x[i] = malloc(128);
     27   pthread_t t[2];
     28   pthread_create(&t[0], 0, Thread1, 0);
     29   pthread_create(&t[1], 0, Thread2, 0);
     30   pthread_join(t[0], 0);
     31   pthread_join(t[1], 0);
     32 }
     33