delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/17/02:47:09

Date: Wed, 17 May 2000 10:08:34 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Tim Updegrove <tdu AT enter DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: Algorithm for integer timing loop
In-Reply-To: <3921dc0e.611684@news.enter.net>
Message-ID: <Pine.SUN.3.91.1000517100806.4709B-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019