Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Nov 1998 21:20:59 -0800 (PST)
From:      Jason Evans <jasone@canonware.com>
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/8872: pthread_cond_timedwait() can cause lost pthread_cond_signal()
Message-ID:  <Pine.BSF.4.05.9811272118380.774-100000@sturm.canonware.com>

next in thread | raw e-mail | index | archive | help

>Number:         8872
>Category:       bin
>Synopsis:       pthread_cond_timedwait() can cause lost pthread_cond_signal()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 27 21:30:00 PST 1998
>Last-Modified:
>Originator:     Jason Evans
>Organization:
>Release:        FreeBSD 2.2.7-STABLE i386
>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 ---------------------------------------------------------------

>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9811272118380.774-100000>