usleep() can't schedule thread and where is the definition of function __mach_reply_port?

Florian Weimer
Tue Jul 10 08:56:00 GMT 2012

On 07/10/2012 10:40 AM, Neil wrote:

> I meet a problem that on routerstation the main thread call
> usleep(100) try to schedule the child thread, but the child thread
> doesn't run sometimes. If main thread call usleep(1000) then the child
> thread will always scheduled. Does anybody meet this problem before?

This could have to do with scheduler granularity.  The kernel probably 
cannot make it back to the calling code in 100 microseconds if it gives 
up the current time slice, so it busy-waits instead.

> Then I check the usleep() code, find that it calls __nanosleep(). In
> __nanosleep(), it seems to call function __mach_reply_port() to handle
> the sleep. But I don't find the definition of __mach_reply_port(),
> there just a declaration in mach/mach/mach_traps.h.

This looks like the Hurd implementation, not sure if this is the correct 
implementation in your case.  On other systems, nanosleep() is a system 
call which is implemented in the kernel, not in libc.

Florian Weimer / Red Hat Product Security Team

More information about the Libc-help mailing list