Desperately missing a working "pselect()" or similar...
Quoted 7 lines
Quoted 3 lines
The select system call doesn't return EINTR when the signal is caught prior to entry into select.
Your friend there is siglongjmp/sigsetjmp - the same problem was true with old versions of alarm that did
Quoted 6 lines
alarm(num) pause()on a heavily loaded box.
Using siglongjmp cures that
Hmmm... would you say the "siglongjmp" method is better than the "self-pipe" method for a select on both file descriptors and signals too?
As far as I can see the trade-off is (in the non-race-condition case) between having to call read() on the pipe (to empty it after receiving the signal) for the "self-pipe" method and having to call sigsetjump() every time before one enters select/poll.
My assumption would be that the "self-pipe" method is cheaper... right?
Then somebody mentioned using signals to wake up processes
for frequent events wouldn't be a good idea at all - why?
And what could be a better alternative given that there are N processes, which all need to be able to wake up any of the other N-1 processes - where N is big enough to prohibit dedicated channels between each possible process pair, and given that it has to be a portable way that does not impose the risk of leaking files to a disk?
Regards,
Lutz Vieweg
--
Dipl. Phys. Lutz Vieweg | email: [email protected] Innovative Software AG | Phone/Fax: +49-69-505030 -120/-505 Feuerbachstrasse 26-32 | http://www.isg.de/people/lkv/ 60325 Frankfurt am Main | ^^^ PGP key available here ^^^
Quoted 2 lines
Hmmm... would you say the "siglongjmp" method is better than the "self-pipe" method for a select on both file descriptors and signals too?
siglongjmp doesnt have to make any syscalls so intuitively I'd say it ought to be more efficient
Quoted 2 lines
Then somebody mentioned using signals to wake up processes for frequent events wouldn't be a good idea at all - why?
Beats me
Alan
Quoted 6 lines · Alan Cox
Quoted 3 lines
Hmmm... would you say the "siglongjmp" method is better than the "self-pipe" method for a select on both file descriptors and signals too?
siglongjmp doesnt have to make any syscalls so intuitively I'd say it ought to be more efficient
Are you sure? Doesn't sigsetjmp() call sigprocmask in order to obtain the current signal mask?
In the glibc I read:
int__sigjmp_save (sigjmp_buf env, int savemask)
{
env[0].__mask_was_saved = (savemask &&
__sigprocmask (SIG_BLOCK, (sigset_t *) NULL,
&env[0].__saved_mask) == 0);
return 0;
}
*sigh* things could be so easy if there was a working pselect()...
Regards,
Lutz vieweg
--
Dipl. Phys. Lutz Vieweg | email: [email protected] Innovative Software AG | Phone/Fax: +49-69-505030 -120/-505 Feuerbachstrasse 26-32 | http://www.isg.de/people/lkv/ 60325 Frankfurt am Main | ^^^ PGP key available here ^^^
Quoted 5 lines
Quoted 2 lines
siglongjmp doesnt have to make any syscalls so intuitively I'd say it ought to be more efficient
Are you sure? Doesn't
sigsetjmp()call sigprocmask in order to obtain the current signal mask?
and intuition is a dangerouns thing. I didnt realise glibc didnt cache the procmask
Quoted 17 lines
Quoted 7 lines
Quoted 3 lines
The select system call doesn't return EINTR when the signal is caught prior to entry into select.
Your friend there is siglongjmp/sigsetjmp - the same problem was true with old versions of alarm that did
Quoted 6 lines
alarm(num) pause()on a heavily loaded box.
Using siglongjmp cures that
Hmmm... would you say the "siglongjmp" method is better than the "self-pipe" method for a select on both file descriptors and signals too?
Quoted 6 lines
As far as I can see the trade-off is (in the non-race-condition case) between having to call
read()on the pipe (to empty it after receiving the signal) for the "self-pipe" method and having to callsigsetjump()every time before one enters select/poll.My assumption would be that the "self-pipe" method is cheaper... right?
Well, but you don't have to call sigsetjmp before every select; just when you enter the loop. Than just enable volatile flag, that the handler should now use the siglongjmp... well, you have to care about 2 signals quickly following one another and similar nasty cases anyway, so the pipe aproach is less error-prone. When signal arives, select either returns EINTR, or says the pipe is ready for writing, so you can save yourself the additional select call by checking for both conditions.
--------------------------------------------------------------------------------
- Jan Hudec `Bulb' <[email protected]>
Quoted 5 lines · Jan Hudec
Well, but you don't have to call sigsetjmp before every select; just when you enter the loop. Than just enable volatile flag, that the handler should now use the siglongjmp... well, you have to care about 2 signals quickly following one another and similar nasty cases anyway, so the pipe aproach is less error-prone.
You don't have to worry about 2 signals following each other if they are the same signal: you can clear the volatile flag in the signal handler.
If they are different signals, e.g. SIGCHLD arrives during SIGINT handler inside select(), then it's more complicated.
The pipe is very simple to get right and at least as fast as a signal handler. Just make sure you can't ever make the mistake of writing to a full pipe. Netscape 4.x does this and that's why it freezes from time to time. It's an easy problem to avoid.
-- Jamie