Subject: sleep, usleep, and nanosleep vs. pthreads?
To: None <>
From: Steven M. Bellovin <>
List: netbsd-users
Date: 09/17/2005 18:32:39
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,