does alarm() work on a per-thread or per-process basis? for example, can each thread in a given process have an independent alarm timer, or does the whole process only get one?
does alarm() work on a per-thread or per-process basis? for example, can each thread in a given process have an independent alarm timer, or does the whole process only get one?
alarm() is signal-based, and signals are per-process. You can control which thread receives a signal to a LIMITED degree. Each thread has its own signal mask. If you block SIGALRM in all threads but one, then that one thread will be the one which receives the signal. If more than one threads has the signal unblocked, it is unspecified which one will receive the signal.
What it boils down to is that there is no easy way to use alarm() in a multi-threaded environment to create simultaneous alarms for multiple threads.
In fact, because of how POSIX defines the signal/thread interactions, signals are rendered pretty much useless for ANY thread-specific uses. They really are a per-process control mechanism.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}