Subject: Re: lib/28700: Re: lib/28700: pthread_cond_timedwait() hang with "zero" absolute time
To: J.T. Conklin <jtc@acorntoolworks.com>
From: Christos Zoulas <christos@zoulas.com>
List: tech-kern
Date: 12/19/2004 14:11:33
On Dec 19,  6:57pm, jtc@acorntoolworks.com (J.T. Conklin) wrote:
-- Subject: lib/28700: Re: lib/28700: pthread_cond_timedwait() hang with "zer

|  In the enclosed patch, I've checked pthread__add_alarm() to detect
|  a zero timeout and to replace it with a one second after the epoch 
|  timeout.  I tried a one-nanosecond after the epoch timeout, but that
|  failed because it was truncated in the timespec->timeval conversion
|  within the kernel.  By my reading of SUSv3, that is probably a bug 
|  in itself.

I think that we should convert all internal times to use timespec, but
until then, this should fix the above problem:

Index: time.h
===================================================================
RCS file: /cvsroot/src/sys/sys/time.h,v
retrieving revision 1.43
diff -u -u -r1.43 time.h
--- time.h      14 Nov 2004 03:30:08 -0000      1.43
+++ time.h      19 Dec 2004 19:08:29 -0000
@@ -66,6 +66,8 @@
 #define        TIMESPEC_TO_TIMEVAL(tv, ts) do {                        \
        (tv)->tv_sec = (ts)->tv_sec;                            \
        (tv)->tv_usec = (ts)->tv_nsec / 1000;                   \
+       if ((tv)->tv_usec == 0 && (ts)->tv_nsec != 0)                   \
+               (tv)->tv_usec++;                                \
 } while (/*CONSTCOND*/0)
 
 /*