Re: C++ stack unwinding
Yang Zhang <[email protected]> Tue, 25 Nov 2008 02:49:14 -0500
| Newsgroups | gmane.comp.lib.state-threads.user |
|---|---|
| Message-ID | <[email protected]> |
Just to be more clear: I'd like stack unwinding to take place in *all*
spawned threads, ideally without another set of bookkeeping state that's
separate from what st already has to manage internally, and without
requiring the user to use another API above ST (and only that API).
The closest solution I've come to so far involves creating another API
on top of ST that will wrap all st_* calls (blocking ones in particular)
in wrappers that throw exceptions on an error. I then also wrap
st_thread_create() in a wrapper that puts the new thread into a global
list of threads, and also wraps the target function in a wrapper that
calls st_thread_interrupt() on all other threads in the global list
whenever an uncaught exception is thrown.
Yang Zhang wrote:
> 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=/