C++ stack unwinding

Yang Zhang <[email protected]> Tue, 25 Nov 2008 01:11:28 -0500
Newsgroups gmane.comp.lib.state-threads.user
Message-ID <[email protected]>
The following simple C++ program does not end up calling the destructor 
because the stack does not get unwound for the threads that aren't part 
of the thread from which SIGABRT is called (by the uncaught exception). 
  Is there a simple way to get stack unwinding to happen properly? 
Thanks in advance.

#include <exception>
#include <iostream>
#include <st.h>
using namespace std;

class cleanup {
   public:
     ~cleanup() { cout << "clean up" << endl; }
};

void *f(void *) {
   throw exception();
   return NULL;
}

int main() {
   cleanup c;
   st_init();
   st_thread_t t = st_thread_create(&f, (void*)"abc", 1, 0);
   st_thread_join(t, NULL);
   return 0;
}

-- 
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=/