4 ms·
No, you can't, because that strategy has a race codition.
by zAy0LfpBZLC8mAC 7y ago
No, you can't, because that strategy has a race codition.
- jschwartzi 7y agoYou should really explain what that race condition is.
- sersnth 7y agoI think they are referring to the fact that the signal could be triggered before the system call is executed, in which case you will miss the signal and the system call will never time out. For example: alarm(1); // alarm could theoretically be triggered here before read() syscall is executed read(...); This sort of problem is what the self pipe trick https://cr.yp.to/docs/selfpipe.html https://cr.yp.to/docs/selfpipe.html is made to solve. I believe it is not really necessary anymore because there are functions like pselect() which solve this by accepting a sigmask parameter. Anyway, most system calls that one would want to have a timeout for have alternatives that accept a timeout parameter.