Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libpthread / cond6 / cond6.c
blobdfd69de6b25de572c39ec858ee617a4334fa6728
1 /* $NetBSD: cond6.c,v 1.1 2004/12/10 17:07:31 nathanw Exp $ */
3 #include <assert.h>
4 #include <err.h>
5 #include <errno.h>
6 #include <pthread.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/time.h>
11 void *threadfunc(void *arg);
13 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
14 pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
16 int main(void)
18 int ret;
19 pthread_t new;
20 struct timespec ts;
21 struct timeval tv;
23 printf("condition variable test 6: bogus timedwaits\n");
25 ret = pthread_mutex_lock(&mutex);
26 if (ret)
27 err(1, "pthread_mutex_lock(1)");
29 printf("unthreaded test (past)\n");
30 gettimeofday(&tv, NULL);
31 tv.tv_sec -= 2; /* Place the time in the past */
32 TIMEVAL_TO_TIMESPEC(&tv, &ts);
34 ret = pthread_cond_timedwait(&cond, &mutex, &ts);
35 if (ret != ETIMEDOUT) {
36 printf("FAIL: pthread_cond_timedwait() (unthreaded)"
37 " in the past returned %d\n", ret);
38 exit(1);
41 printf("unthreaded test (zero time)\n");
42 tv.tv_sec = 0;
43 tv.tv_usec = 0;
44 TIMEVAL_TO_TIMESPEC(&tv, &ts);
46 ret = pthread_cond_timedwait(&cond, &mutex, &ts);
47 if (ret != ETIMEDOUT) {
48 printf("FAIL: pthread_cond_timedwait() (unthreaded)"
49 " with zero time returned %d\n", ret);
50 exit(1);
53 ret = pthread_create(&new, NULL, threadfunc, NULL);
54 if (ret != 0)
55 err(1, "pthread_create");
56 ret = pthread_join(new, NULL);
57 if (ret != 0)
58 err(1, "pthread_join");
60 printf("threaded test\n");
61 gettimeofday(&tv, NULL);
62 tv.tv_sec -= 2; /* Place the time in the past */
63 TIMEVAL_TO_TIMESPEC(&tv, &ts);
65 ret = pthread_cond_timedwait(&cond, &mutex, &ts);
66 if (ret != ETIMEDOUT) {
67 printf("FAIL: pthread_cond_timedwait() (threaded)"
68 " in the past returned %d\n", ret);
69 exit(1);
72 printf("threaded test (zero time)\n");
73 tv.tv_sec = 0;
74 tv.tv_usec = 0;
75 TIMEVAL_TO_TIMESPEC(&tv, &ts);
77 ret = pthread_cond_timedwait(&cond, &mutex, &ts);
78 if (ret != ETIMEDOUT) {
79 printf("FAIL: pthread_cond_timedwait() (threaded)"
80 " with zero time returned %d\n", ret);
81 exit(1);
84 pthread_mutex_unlock(&mutex);
86 return 0;
89 void *
90 threadfunc(void *arg)
92 return NULL;