Subject: Re: Two questions
To: Mihai CHELARU <>
From: Nathan J. Williams <>
List: current-users
Date: 04/28/2003 13:46:36
Mihai CHELARU <> writes:

> On Monday 28 April 2003 10:34, Mihai CHELARU wrote:
> > 2) Anyone is experiencing problems using threads and time wait
> > functions like nanosleep (or usleep) and pthread_cond_timedwait ?
> > Using those in a code results in infinite (sa)wait. Could be my poor
> > code or something else, just want to check.
> for (;;) {
>         p=fork ();
>         if (p<=0) break;
>         waitpid (p,NULL,0);
>         return 0;
> }

The call to fork() made me suspicious that this code was correct,
since there are restrictions on the use of fork() in a multithreaded
program. However, threads haven't been created yet when this is
called, so that's OK.

I found that part of the early libpthread initialization - setting up
the timer structures used by the alarm and sleep code - is done too
early, when the library is loaded, rather than at the first call to
pthread_create(). Fixed in src/lib/libpthread/pthread.c rev 1.18. With
that fix, your test program appears to run correctly (although the
"while (i>0)" loop in th2 seems like it's missing something).

        - Nathan