From jasone@canonware.com  Fri Nov 27 21:24:06 1998
Received: from sturm.canonware.com (canonware.com [204.107.140.54])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id VAA05103
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Nov 1998 21:24:05 -0800 (PST)
          (envelope-from jasone@canonware.com)
Received: from localhost (jasone@localhost)
	by sturm.canonware.com (8.8.8/8.8.8) with ESMTP id VAA00781
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Nov 1998 21:21:00 -0800 (PST)
	(envelope-from jasone@canonware.com)
Message-Id: <Pine.BSF.4.05.9811272118380.774-100000@sturm.canonware.com>
Date: Fri, 27 Nov 1998 21:20:59 -0800 (PST)
From: Jason Evans <jasone@canonware.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: pthread_cond_timedwait() can cause lost pthread_cond_signal()

>Number:         8872
>Category:       bin
>Synopsis:       pthread_cond_timedwait() can cause lost pthread_cond_signal()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 27 21:30:00 PST 1998
>Closed-Date:    Fri May 7 01:25:24 PDT 1999
>Last-Modified:  Fri May  7 01:26:59 PDT 1999
>Originator:     Jason Evans
>Release:        FreeBSD 2.2.7-STABLE i386
>Organization:
>Environment:

FreeBSD orkan 2.2.7-STABLE FreeBSD 2.2.7-STABLE #0:
 Thu Nov 26 09:13:44 PST 1998    
 toor@orkan:/usr/src/sys/compile/CRASH_orkan  i386

>Description:

pthread_cond_timedwait() causes a thread to be unscheduled for a specified
period of time, unless a condition becomes true.  If that timeout expires, the
thread is rescheduled, but it is left on the condition wait queue.  This can
cause a pthread_cond_signal() to be lost.

>How-To-Repeat:

1) Call pthread_cond_timedwait() in thread A.
2) Let the timer expire.
3) Call pthread_cond_wait() in thread B.
4) Call pthread_cond_signal() in thread A.
*** The signal will have no effect.
5) Call pthread_cond_signal() again in thread A.
*** Thread B will be signaled.

>Fix:
It looks safe to ignore the return value of _thread_queue_remove(), but I
may be mistaken.

--- Begin patch -------------------------------------------------------------
*** /usr/src/lib/libc_r/uthread/uthread_kern.c.orig     Fri Nov 27 16:10:16 1998
--- /usr/src/lib/libc_r/uthread/uthread_kern.c  Fri Nov 27 16:05:16 1998
***************
*** 171,176 ****
--- 171,185 ----
                                                FD_ZERO(&pthread->data.select_da
ta->writefds);
                                                FD_ZERO(&pthread->data.select_da
ta->exceptfds);
                                                pthread->data.select_data->nfds 
= 0;
+                                       } else if (pthread->state == PS_COND_WAI
T) {
+                                               /*
+                                                * The pthread_cond_timedwait()
+                                                * has timed out, so remove the
+                                                * thread from the condition's
+                                                * queue.
+                                                */
+                                               _thread_queue_remove(pthread->qu
eue,
+                                                                    pthread);
                                        }
  
                                        /*
--- End patch ---------------------------------------------------------------

>Release-Note:
>Audit-Trail:

From: "David Schwartz" <davids@webmaster.com>
To: <freebsd-gnats-submit@freebsd.org>, <jasone@canonware.com>
Cc:  
Subject: Re: bin/8872: pthread_cond_timedwait() can cause lost pthread_cond_signal()
Date: Mon, 15 Mar 1999 10:16:30 -0800

 	This bug was causing crashes in the FreeBSD version of ConferenceRoom. It
 really should be fixed ASAP. Thanks for the workaround, Jason.
 
 	David Schwartz
 	Director of Software Development
 	WebMaster, Incorporated
 	http://www.webmaster.com/
 
 
 

From: Jason Evans <jasone@canonware.com>
To: David Schwartz <davids@webmaster.com>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/8872: pthread_cond_timedwait() can cause lost pthread_cond_signal()
Date: Mon, 15 Mar 1999 10:33:17 -0800 (PST)

 On Mon, 15 Mar 1999, David Schwartz wrote:
 > 	This bug was causing crashes in the FreeBSD version of
 > ConferenceRoom. It really should be fixed ASAP. Thanks for the
 > workaround, Jason.
 
 I have commit access now, and am just waiting to be added to the
 -committers list before committing this, so it should be fixed soon.
 
 Jason
 
 Jason Evans <jasone@canonware.com>
 http://www.canonware.com/~jasone
 Home phone: (650) 856-8204
 Work phone: (415) 808-8742
 "I once knew a happy medium.  Her name was Zohar." - James Foster
 
 

From: "David Schwartz" <davids@webmaster.com>
To: <freebsd-gnats-submit@freebsd.org>, <jasone@canonware.com>
Cc:  
Subject: Re: bin/8872: pthread_cond_timedwait() can cause lost pthread_cond_signal()
Date: Thu, 22 Apr 1999 02:43:07 -0700

 	Any idea when this will get committed? Can someone else commit it?
 Anything, please...
 
 	DS
 
 
State-Changed-From-To: open->closed 
State-Changed-By: jasone 
State-Changed-When: Fri May 7 01:25:24 PDT 1999 
State-Changed-Why:  
>Unformatted:
