Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 09 Oct 2008 09:25:56 +0800
From:      David Xu <davidxu@freebsd.org>
To:        John Hein <jhein@timing.com>
Cc:        threads@freebsd.org
Subject:   Re: pthread_cleanup_push & pthread_cleanup_pop usage
Message-ID:  <48ED5DA4.9060803@freebsd.org>
In-Reply-To: <18668.10465.699531.162573@gromit.timing.com>
References:  <18668.10465.699531.162573@gromit.timing.com>

next in thread | previous in thread | raw e-mail | index | archive | help
John Hein wrote:
> In June pthread_cleanup_push & pthread_cleanup_pop were changed to macros
> that look like so...
> 
> +#define        pthread_cleanup_push(cleanup_routine, cleanup_arg)              \
> +               {                                                               \
> +                       struct _pthread_cleanup_info __cleanup_info__;          \
> +                       __pthread_cleanup_push_imp(cleanup_routine, cleanup_arg,\
> +                               &__cleanup_info__);                             \
> +                       {
> +
> +#define        pthread_cleanup_pop(execute)                                    \
> +                       }                                                       \
> +                       __pthread_cleanup_pop_imp(execute);                     \
> +               }
> +
> 
> 
> This breaks code where the pop is done in an inner block level.
> 
> simplified example:
> 
>     pthread_cleanup_push(docleanup, &foo);
>     try
>     {   
>         dostuff();
>     }
>     catch (...)
>     {   
>         pthread_cleanup_pop(1);
>         throw;
>     }
>     pthread_cleanup_pop(1);
> 
> Does anyone have a recommended fix?


Your problem can be fixed as deischen@ said. but I think it can be
resolved by stack unwinding code I am working in progress, when a
C++ exception is thrown, onstack C++ objects along with pthread
cleanup handlers will be invoked automatically.

Regards,
David Xu




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?48ED5DA4.9060803>