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

Dr Mark H Phillips mark at austrics.com.au
Mon Feb 17 13:32:02 UTC 2003


Some more info on the problem...

I did a test on the cout stream near where the problem occurs
and it seems the ^C interrupt puts cout into a "failed state"!

This raises two questions.  Firstly, why should jumping to an
interrupt handler put cout into a failed state.  Secondly,
how can this problem be overcome, ie how can one ensure that
interrupt handling doesn't cause cout to fail?  Thirdly, if
it is possible for cout to fail, does this mean that we really
should be putting tests for failure throughout our code?!!  This
would be a huge amount of work and very messy?!!!

Thoughts anyone.

Cheers,

Mark.

On Mon, 2003-02-17 at 15:20, Dr Mark H Phillips wrote:
> 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
> 
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List
-- 
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