please help: signals, exceptions and g++

Kevin D. Clark kclark at CetaceanNetworks.com
Sun Jan 25 23:34:29 EST 2004


Frank Ramsay writes:

> I'm trying to write a signal handler that will convert the signal into
> a C++ style exception, but
...
> So here is my questions;
> Is it possible to do this in a safe consistant maner?
> And what am I doing wrong?

I've worked with some code in the past that did exactly this.  My
advice to you:  avoid this if possible.

The code that I worked with a few years ago worked because it happened
to be developed and run on a Solaris machine using Sun's compiler
(note: I didn't write this code).  It was my experience that when I
ported such code over to other platforms, that this technique didn't
port very easily.  Sun's compiler and runtime (C++ runtime, OS
signal-handling semantics) worked in concert to make this feature work
nicely.  But other platforms basically blew up when they encountered
this.

So, again, I would avoid this technique  ***.


>       std::cout << "catch: " << except << std::endl;

Another thing:  you might want to consider avoiding use of the
iostreams library in multi-threaded programs, unless your iostreams
library provides some sort of locking functionality and your program
uses this.  Otherwise you can end up with interleaved garbage.

Regards,

--kevin

*** However, one of the goals of Linux's new NPTL is C++
    compatability, and I am led to believe that NPTL will have better
    support for this sort of functionality.  If you happened to be
    targetting machines that utilized this library, you might be OK.
    Maybe.  You'd need to investigate this.  Oh, and make sure you're
    using the correct compiler too.

-- 
"I don't know what was wrong with my program, but I put in a call to
java.lang.Thread.yield() and it fixed it!"
-- clownboy




More information about the Discuss mailing list