Subject: Re: sleep, usleep, and nanosleep vs. pthreads?
To: Steven M. Bellovin <smb@cs.columbia.edu>
From: Florian Stoehr <netbsd@wolfnode.de>
List: netbsd-users
Date: 09/18/2005 00:50:36
On Sat, 17 Sep 2005, Steven M. Bellovin wrote:
> I'm trying to get gtkpod working on NetBSD. When I ran it, it went
> into an CPU-chewing loop in the following code:
>
> /* keep space_ipod_free/used updated in regular intervals */
> static gpointer th_space_thread (gpointer gp)
> {
> for (;;)
> {
> usleep (SPACE_TIMEOUT*1000);
> if (!space_uptodate) th_space_update ();
> }
> }
>
> Contrary to the usleep call -- SPACE_TIMEOUT is 4000, so it should have
> been a 4-second sleep -- it seemed to return either immediately or
> virtually immediately. Changing it to use nanosleep didn't help.
> However, using sleep() made it work.
>
> I'm puzzled. However, I know nothing of pthreads, so I don't know if
> some special invocation should have been used by gtkpod to make that
> work. The problem with usleep occurs on 2.0 and -current; the fix
> works on -current and hasn't been tried yet on 2.0.
>
> --Steven M. Bellovin, http://www.cs.columbia.edu/~smb
>
From the manpage of usleep(3):
The microseconds argument must be less than 1,000,000. If the value
of microseconds is 0, then the call has no effect.
It should set errno to EINVAL then.
-Florian