logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anatoly Kournik <Anato...@enigma.com>
Subject Thread::sleep() implementation bug on Solaris
Date Mon, 13 Sep 2004 08:15:02 GMT
using usleep in Thread::sleep() implementation on Unix(Solaris) is
problematic in multithreaded environment
because  it's implemented by setting an alarm signal and pausing until it
Since SIGALRM shouldn't be blocked or ignored during a call, if context
switch occurs when it's delivered, the programm simply quits (default action
The proper way is to use nanosleep function. It has no effect on the action
or blockage of any signal.
Here is an example of nanosleep usage.
I've encapsulated call to nanosleep in signal blocking/unblocking routines
in order to prevent signals delivery. 
sigset_t newset, oldset;


pthread_sigmask(SIG_BLOCK, &newset, &oldset);//block signals

struct timespec sleeptime;

sleeptime.tv_sec = ms / 1000; //argument is supplied in milliseconds

sleeptime.tv_nsec = 0; 

if(nanosleep(&sleeptime, NULL)) perror("nanosleep");

pthread_sigmask(SIG_SETMASK, &oldset, NULL);//restore signals

Toly Kournik
This email and any files transmitted with it are confidential and intended solely for the
use of the individual or entity to whom
they are addressed. If you have received this email in error please notify the originator
of the message.
Scanning of this message is performed by SurfControl E-mail Filter software in conjunction
with  virus detection software.

View raw message