logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anatoly Kournik <Anato...@enigma.com>
Subject RE: Thread::sleep() implementation bug on Solaris
Date Wed, 22 Sep 2004 07:57:43 GMT
Could somebody react on my mail.
 
thanks,
Toly Kournik

-----Original Message-----
From: Anatoly Kournik [mailto:AnatolyK@enigma.com]
Sent: Monday, September 13, 2004 11:15 AM
To: log4cxx-user@logging.apache.org
Subject: Thread::sleep() implementation bug on Solaris


Hi,
 
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
occurs.
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
on SIGALRM).
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;

sigfillset(&newset);

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.


--------------------------------------------------------------------------------------------------------------------------------------------------------------
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.

Mime
View raw message