From nobody  Thu Oct 15 09:25:05 1998
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.8/8.8.8) id JAA15891;
          Thu, 15 Oct 1998 09:25:05 -0700 (PDT)
          (envelope-from nobody)
Message-Id: <199810151625.JAA15891@hub.freebsd.org>
Date: Thu, 15 Oct 1998 09:25:05 -0700 (PDT)
From: info@highwind.com
To: freebsd-gnats-submit@freebsd.org
Subject: pthread_cond_timedwait() is broken
X-Send-Pr-Version: www-1.0

>Number:         8335
>Category:       kern
>Synopsis:       pthread_cond_timedwait() is broken
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 15 09:30:00 PDT 1998
>Closed-Date:    Thu Oct 15 11:10:03 PDT 1998
>Last-Modified:  Thu Oct 15 11:10:53 PDT 1998
>Originator:     Robert Fleischman
>Release:        3.0
>Organization:
HighWind Software
>Environment:
FreeBSD zonda.highwind.com 3.0-19980831-SNAP FreeBSD 3.0-19980831-SNAP #0: Mon Aug 31 14:03:19 GMT 1998     root@make.ican.net:/usr/src/sys/compile/GENERIC  i386

>Description:
It appears that in recent 3.0 kernels, pthread_cond_timedwait() doesn't
work properly. This is true even with the latest libc_r.

I've included a test program.
>How-To-Repeat:
/* Illustration of FreeBSD pthread_cond_timedwait() bug
   
   This program sets up a timed conditional wait. It just calls
   cond_timed_wait(). This should BLOCK for 15 seconds and the program
   should terminate normally.

   However, because of some bugs in FreeBSD, the cond_timed_wait
   returns with no error. It looks as if someone has signaled the
   condition. Clearly, that is impossible and there is some kind of bug!

   g++ -o condBug -D_REENTRANT -D_THREAD_SAFE -g -Wall condBug.C -pthread 
*/

#include <assert.h>
#include <pthread.h>
#include <stdlib.h>

int main(int, char **)
{
    pthread_mutex_t lock;
    pthread_cond_t condition;

    // Initialize Lock
    pthread_mutexattr_t lock_attr;
    assert(!::pthread_mutexattr_init(&lock_attr));
    assert(!::pthread_mutex_init(&lock, &lock_attr));
    assert(!::pthread_mutexattr_destroy(&lock_attr));

    // Initialize Condition
    pthread_condattr_t cond_attr;
    assert(!::pthread_condattr_init(&cond_attr));
    assert(!::pthread_cond_init(&condition, &cond_attr));
    assert(!::pthread_condattr_destroy(&cond_attr));

    // Grab current time
    time_t currentTime = ::time(0);

    // Lock the lock
    assert(!::pthread_mutex_lock(&lock));

    // Wait in the condition for 15 seconds
    timespec timeOut;
    timeOut.tv_sec = currentTime + 15;
    timeOut.tv_nsec = 0;
    
    int err = ::pthread_cond_timedwait(&condition, &lock, &timeOut);

    // We better get an error (we should have TIMED OUT!)
    assert(err);

    // 15 seconds SHOULD have passed, so 5 seconds DEFINATELY should have!!
    assert(::time(0) >= currentTime + 5);

    return EXIT_SUCCESS;
}

>Fix:

>Release-Note:
>Audit-Trail:

From: Dmitrij Tejblum <tejblum@arc.hq.cti.ru>
To: info@highwind.com
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: kern/8335: pthread_cond_timedwait() is broken 
Date: Thu, 15 Oct 1998 21:58:23 +0400

 I am unable to reproduce this problem on 3 different machines with latest 
 libc_r and reasonable current kernels. (As I know, I am not alone...)
 
 Dima
 
 

From: HighWind Software Information <info@highwind.com>
To: tejblum@arc.hq.cti.ru
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: kern/8335: pthread_cond_timedwait() is broken
Date: Thu, 15 Oct 1998 14:04:47 -0400 (EDT)

 I would like that bug to be removed. The very latest libc_r seems to 
 fix the problem.
 
 After CAREFULLY rebuilding our libc_r (prefaced by a "make clean")
 it seems the problem is NOT reproduceble.
 
 Feel free to close the bug.
 
 -Rob "quite red faced for not typing 'make clean'"
State-Changed-From-To: open->closed 
State-Changed-By: dt 
State-Changed-When: Thu Oct 15 11:10:03 PDT 1998 
State-Changed-Why:  
Closed on originator's request. 
>Unformatted:
