[LC++]Interrupt signals and streams - a bad mix?

Dr Mark H Phillips mark at austrics.com.au
Mon Feb 17 12:42:01 UTC 2003


Hi,

I have a program which, when ^C-ed, tidys itself up and then
exits.  The code that sets up the interrupt looks like this:

  switch (sig) {
  ...
  case SIGINT:
    logm<<"SIGINT ("<<sig<<") received."<<endl;
    windup = 1;
    signal(sig, SIG_DFL);
    break;
  ...

The windup variable is global and normally is 0.  When ^C
is detected, it sets windup to 1, changes things so that
if ^C is used a second time it will exit in the normal
way, and then goes back to where it left off in the
program.

Meanwhile, in the guts of the program, it periodically checks
for windup, and if set, goes about winding things up in a neat
way.

Mostly this has worked well, but I've come across a problem.
Sometimes, when it is ^C-ed in the middle of outputting to
a stream, the stream seems to be stuffed up and it gets into
an infinite loop of writing "\n" to the file (which in this
case is cout).

Are streams known to interact badly with interrupts?

Has anyone got ideas about what could be going wrong and how
to fix things?

Thanks,

Mark.

-- 
Dr Mark H Phillips
Research Analyst (Mathematician)

AUSTRICS - smarter scheduling solutions - www.austrics.com

Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
Phone +61 8 8226 9850
Fax   +61 8 8231 4821
Email mark at austrics.com.au




More information about the tuxCPProgramming mailing list