NetBSD Problem Report #41645

From  Sun Jun 28 17:50:19 2009
Return-Path: <>
Received: from ( [])
	by (Postfix) with ESMTP id EFA4463B976
	for <>; Sun, 28 Jun 2009 17:50:18 +0000 (UTC)
Message-Id: <>
Date: Sun, 28 Jun 2009 17:50:18 +0000 (UTC)
Subject: pthread_cond_timedwait(3) doesn't timeout if NULL is given as abstime argument
X-Send-Pr-Version: www-1.0

>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);


NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD:,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.