DragonFly BSD
DragonFly users List (threaded) for 2005-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Question about threading implementation

From: Andrew Hacking <ahacking@xxxxxxxxxxxxxxx>
Date: Tue, 08 Mar 2005 11:31:21 +1000

On Mon, 2005-03-07 at 22:24, Jonathon McKitrick wrote: 
> On Mon, Mar 07, 2005 at 11:43:53AM +1000, Andrew Hacking wrote:
> : Calling sleep() in a multi-threaded program is probably not safe since
> : it suspends the process, not just the thread.
> : You should always call nanosleep() in multi-threaded apps.
> Are you sure nanosleep() doesn't suspend the process?

As sure as I can be. ;-)

I remember experiencing a number of problems with sleep() on at least
one or more unix variants when using threads.
However I have used nanosleep() successfully on FreeBSD, Solaris, Linux,
AIX and HP-UX.

The FreeBSD implementation of sleep() is based on nanosleep() [according
to the man page] so I was probably wrong to say don't use sleep() in
your particular case,  there should be nothing to worry about on
FreeBSD/DFly.  However if you prefer portable thread-safe code,
nanosleep() is the best sleeping variant to use. On many unix variants
sleep() will not work correctly when using threads because the
implementation of sleep() often relies on signals.


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]