Subject: Re: Possible issue with pthread conditions
To: None <netbsd-help@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-help
Date: 08/23/2004 07:57:53
In article <41299D61.1090901@partow.net>,
Arash Partow <arash@partow.net> wrote:
>Hello all,
>
>I'm having some issues with pthreads and pthread conditions, I've
>written a simple test case scenario, when I run it within a few
>seconds of the application running the following message appears:
>
>POSIXThreadConditionTest: Error detected by libpthread: Invalid wait time.
>Detected by file "usr/local/src/lib/libpthread/pthread_cond.c", line
>187, function "pthread_cond_timedwait".
>See pthread(3) for information.
>
>The test case makes a number of threads, each thread has a local
>condition variable from which it invokes the pthread_cond_timedwait
>function. The thread will invoke the function with 40 different time-out
>values, ranging from 1ms to 167ms. Once the thread has finished its task
>it goes into a dead state where-by it is cleaned-up and a new thread is
>instantiated to take its place. The test just repeats itself over and
>over until the user fires a SIG-INT.
>
>I'm not sure if the problems I'm seeing is related to what I'm doing (my code)
>or whether its a NetBSD related issue.
>
>I was hoping a few kind people could have a go at running this code
>and tell me if they too see this error, I would like to be certain its
>a bug related to the OS before I write a problem report. I've uploaded
>the test and it can be downloaded from the following url:
>
>http://www.partow.net/netbsd/netbsd-problem-23-08-2004.tgz

This is a bug in your code. You need to check that tv_nsec is less
than 1000000000. Something like:

  while (timeout.tv_nsec >= 1000000000) {
        timeout.tv_nsec -= 1000000000;
        timeout.tv_sec++;
  }   

will do it.

christos