[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Hanlding SIGSEGV/SIGBUG with glibc 2.3.2
From: |
Wolfram Gloger |
Subject: |
Re: Hanlding SIGSEGV/SIGBUG with glibc 2.3.2 |
Date: |
29 Jun 2004 10:11:52 -0000 |
Hello,
> Since I can not do anything usefull in the signal handler (in praticular
> - cleanup) - can I use threads for the cleanup. I currently do not use
> threads in my code but from browsing in the man pages, it looks to me
> that I should be able to do the cleanup in a separate thread (assuming
> that the memory has not been corrupted).
Personally, I would think twice about adding threads just for this
functionality.
> I'm thinking about:
>
> pthread_t main_thread ;
> int done_ok ;
>
> main() {
> main_thread = pthread_self() ;
> pthread_create (..., monitor_main, ...)
> ... actual code here ...
> cleanup()
> exit()
> }
>
> cleanup {
> if ( need_cleanup ) {
> need_clenaup = 0
> ... Actual Cleanup ...
> }
>
> monitor_main {
> pthread_join(main_thread)
> cleanup()
> }
This wouldn't work, because you would need to call pthread_exit()
from the SIGSEGV handler, and that isn't allowed.
You could poll in the monitor_main() thread:
monitor_main
{
for(;;) {
if (need_cleanup)
...
sleep(1)
}
}
but I still thing exec()ing a helper app would be better.
Regards,
Wolfram.