10 void *threadfunc(void *arg
);
12 pthread_mutex_t mutex
;
15 main(int argc
, char *argv
[])
21 printf("1: Mutex-test 1\n");
23 pthread_mutex_init(&mutex
, NULL
);
25 pthread_mutex_lock(&mutex
);
26 ret
= pthread_create(&new, NULL
, threadfunc
, &x
);
28 err(1, "pthread_create");
29 printf("1: Before changing the value.\n");
32 printf("1: Before releasing the mutex.\n");
34 pthread_mutex_unlock(&mutex
);
35 printf("1: After releasing the mutex.\n");
36 ret
= pthread_join(new, &joinval
);
38 err(1, "pthread_join");
40 pthread_mutex_lock(&mutex
);
41 printf("1: Thread joined. X was %d. Return value (int) was %d\n",
44 assert(*(int *)joinval
== 21);
45 pthread_mutex_unlock(&mutex
);
54 printf("2: Second thread.\n");
57 printf("2: Locking mutex\n");
58 pthread_mutex_lock(&mutex
);
59 printf("2: Got mutex. *param = %d\n", *param
);
63 pthread_mutex_unlock(&mutex
);