NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/41645: pthread_cond_timedwait(3) doesn't timeout if NULL is given as abstime argument

>Number:         41645
>Category:       lib
>Synopsis:       pthread_cond_timedwait(3) doesn't timeout if NULL is given as 
>abstime argument
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jun 28 17:55:00 +0000 2009
>Originator:     Stathis Kamperis
>Release:        NetBSD 5.0_STABLE
Aristotle University of Thessaloniki
NetBSD voyager 5.0_STABLE NetBSD 5.0_STABLE (MYGENERIC) #6: Fri Jun 26 22:50:50 
EEST 2009  root@voyager:/usr/obj/sys/arch/i386/compile/MYGENERIC i386

The pthread_cond_timedwait(3) functions waits perpetually if `NULL' is supplied 
as `abstime' argument. POSIX (issue 6) says that if an invalid timeout is 
given, EINVAL should be returned immediately. Issue 7, doesn't talk about 
invalid timeout, it just gives a valid range.

According to my understanding, a programmer using pthread_cond_timedwait(3) 
would want the call to timeout at some point. So if by mistake provides a NULL 
timeout, what's the least surprise thing we could do ? Error or block 
indefinitely ?

I realize that my argument is flammable. So even if you expect the programmer 
to always do the right thing or the current state is a conscious design that I 
miss, could you please document this behavior in pthread_cond_timedwait(3) man 
page ?

Best regards,


#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
        pthread_cond_t cond;
        pthread_mutex_t mtx;
        struct timespec abstime;

        /* Create a condition variable with default attributes. */
        assert(pthread_cond_init(&cond, NULL) == 0);

        /* Initialize mutex. */
        assert(pthread_mutex_init(&mtx, NULL) == 0);

        /* Acquire lock. */
        assert(pthread_mutex_lock(&mtx) == 0);

        assert(pthread_cond_timedwait(&cond, &mtx, NULL) == EINVAL);

        /* Release lock. */
        assert(pthread_mutex_unlock(&mtx) == 0);

        /* Cleanup. */
        assert(pthread_cond_destroy(&cond) == 0);
        assert(pthread_mutex_destroy(&mtx) == 0);


        return (EXIT_SUCCESS);


Home | Main Index | Thread Index | Old Index