Reputation: 30765
I saw that semaphores in my application were not always working as expected. Then I was told that this unexpected behavior can be caused when a signal interrupts the sem_wait
call.
So, my question is what care needs to be taken by the programmer in the presence of signals. For sem_wait
, we can check for the return values, but is this the same for all non-async safe functions? And what else we should keep in mind when expecting signals to interrupt our code?
Upvotes: 0
Views: 113
Reputation:
UNIX signals is a can of worm, just to have said that.
There's 2 camps regarding syscalls and signals.
When using the signal(), the default is one of the two above, with BSD systems and Linux defaulting to BSD semantics, and everyone[citation needed..] else have the SysV semantics. (On Linux, this depends on many things, e.g. compiling with -std=c99 gives SysV semantics, with -std=gnu99 gives BSD semantics. See e.g. http://www.gnu.org/s/hello/manual/libc/Interrupted-Primitives.html)
When you install a signal handler with sigaction(), you get to chose which semantics with the SA_RESTART flags.
Basically:
EDIT: edited, as I mixed up BSD vs Sysv semantics.
Upvotes: 2