32 ms·
> Another way to avoid the race condition in poll/select, before p{poll/select} were standardized, was to store the timeout parameter in a global variable and h
by zAy0LfpBZLC8mAC 10y ago
> Another way to avoid the race condition in poll/select, before p{poll/select} were standardized, was to store the timeout parameter in a global variable and have the signal handler set it to zero.
That doesn't work. At some point, the userspace code has to copy the value from the global variable to the location where the system call calling convention expects it, some time later followed by execution of the system call trap (and usually there is even the libc system call wrapper in between the two that takes care of adapting the userspace calling convention to the system call calling convention). If your signal handler gets to run in between the two, the system call timeout will remain unchanged.
Or in other words: Yes, be afraid of signals, whatever clever scheme you come up with to handle them probably is wrong.
- gpderetta 10y agoIt works with select because it takes a pointer to the timespec object, which is read kernel side [1]. I misremembered poll doing the same thing but it takes a plain integer parameter. [1] not guaranteed of course, but it is historical Unix behaviour Edit: btw, i do agree with your final sentence!