1 /* $NetBSD: cond6.c,v 1.1 2004/12/10 17:07:31 nathanw Exp $ */
11 void *threadfunc(void *arg
);
13 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
14 pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
23 printf("condition variable test 6: bogus timedwaits\n");
25 ret
= pthread_mutex_lock(&mutex
);
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
);
41 printf("unthreaded test (zero time)\n");
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
);
53 ret
= pthread_create(&new, NULL
, threadfunc
, NULL
);
55 err(1, "pthread_create");
56 ret
= pthread_join(new, NULL
);
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
);
72 printf("threaded test (zero time)\n");
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
);
84 pthread_mutex_unlock(&mutex
);