Mail Archives: djgpp/2000/05/17/02:47:09
On Tue, 16 May 2000, Tim Updegrove wrote:
> A user of my program may terminate it with a Ctrl+C because they are
> impatient waiting for some event or if the program hangs (I'm
> implementing timeouts so this will occur less).
The problem only happen if Ctrl-C is pressed while `uclock's code
runs. If your program calls `uclock' a lot in a tight loop, the
probability of this happening is high, and you will need to take
control of Ctrl-C (and Ctrl-BREAK).
> I'm not familiar with how to block SIGINT. Do I need to block it for
> the entire program or just before & after calling uclock?
Does your program use `uclock' all the time? If so, it will be better
to install a handler for SIGINT (using `signal') that will cause an
orderly exit, instead of letting the library default to abort the
program. For example, you could have the SIGINT handler increment a
flag variable and return. Then the mainline code could check this
variable and call `exit' if it is non-zero. I've verified with a
variant of your test program that doing so seems to avoid disrupting
`uclock' in later program invocations.
If the program calls `uclock' only during short periods, like at the
beginning, when measuring the CPU speed, then it might be better to
block SIGINT during that period (using `sigprocmask') and unblock it
afterwards.
> I'm also not familiar with 'signal' and the other 2 items. I guess
> they are ways to terminate programs or at least provide some flag to a
> program?
I suggest a good reading of the library docs ;-). Both `signal' and
`sigprocmask' are extensively documented in libc.info, including
examples. If, after reading, something is unclear, please ask
specific questions.
- Raw text -