1 /* $NetBSD: mutex3.c,v 1.1 2003/01/30 18:05:26 thorpej Exp $ */
9 void *threadfunc(void *arg
);
11 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
15 main(int argc
, char *argv
[])
17 int count
, count2
, ret
;
21 printf("1: Mutex-test 3\n");
24 count
= count2
= 10000000;
25 ret
= pthread_mutex_lock(&mutex
);
27 err(1, "pthread_mutex_lock (1)");
28 ret
= pthread_create(&new, NULL
, threadfunc
, &count2
);
30 err(1, "pthread_create");
32 printf("1: Thread %p\n", pthread_self());
33 ret
= pthread_mutex_unlock(&mutex
);
35 err(1, "pthread_mutex_unlock(1)");
39 ret
= pthread_mutex_lock(&mutex
);
41 err(1, "pthread_mutex_lock(2)");
43 ret
= pthread_mutex_unlock(&mutex
);
45 err(1, "pthread_mutex_unlock(2)");
48 ret
= pthread_join(new, &joinval
);
50 err(1, "pthread_join");
52 pthread_mutex_lock(&mutex
);
53 printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
55 assert(x
== 20000000);
62 long count
= *(int *)arg
;
65 printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count
);
68 ret
= pthread_mutex_lock(&mutex
);
70 err(1, "pthread_mutex_lock(3)");
72 ret
= pthread_mutex_unlock(&mutex
);
74 err(1, "pthread_mutex_unlock(3)");