Re: C++ stack unwinding

Yang Zhang <[email protected]> Mon, 01 Dec 2008 13:14:38 -0500
Newsgroups gmane.comp.lib.state-threads.user
Message-ID <[email protected]>
Mike Abbott wrote:
>> I'd like stack unwinding to take place in *all* spawned threads
> 
> As you discovered, ST has no knowledge of C++ exceptions.
> 
> However, I think you may be relying on platform-specific behavior.  My
> understanding of uncaught exceptions is that they result in terminate()
> being called, which defaults to abort(), which means no destructors are
> called for any objects.  If you remove all the ST functions from your
> test program and simply throw an uncaught exception:
> 
> [...]
> int main() {
>    cleanup c;
> //   st_init();
> //   st_thread_t t = st_thread_create(&f, (void*)"abc", 1, 0);
> //   st_thread_join(t, NULL);
>    f(NULL);
>    return 0;
> }
> 
> then c's destructor is not called either.  This matches what my copy of
> Stroustrup says.  Does something different happen on your system?

Interesting!  The same also happens for me.  I always thought that 
destructors/RAII was the C++ way to do `finally`, but I suppose it comes 
with a caveat about the top-level composition of the program properly 
catching all exceptions.  Surprisingly, I can't find much other 
discussion of this on the web.

> 
> On the other hand, if you were trying to have thread A *catch* an
> exception thrown by thread B, then I could understand your desire to
> have stack unwinding work properly and have object c's destructor
> called.  But ST does not support propagating C++ exceptions across
> threads.  ST does work just fine with C++ -- I have done so myself --
> just not when it comes to exceptions crossing threads.

After thinking about this some more, I'm not sure I can do this at all. 
  Even if I used RTTI to determine the dynamic type of the exception, 
catches operate on the static type of the exception.

> 
> 
> 
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> State-threads-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/state-threads-users


-- 
Yang Zhang
http://www.mit.edu/~y_z/

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/