pthread_cleanup_push & pthread_cleanup_pop usage
Alfred Perlstein
alfred at freebsd.org
Wed Oct 8 05:12:16 UTC 2008
* John Hein <jhein at timing.com> [081007 21:45] wrote:
> In June pthread_cleanup_push & pthread_cleanup_pop were changed to macros
> that look like so...
Hey John, I found the same problem when working on QNX a while back,
however that is really how it's supposed to be set up.
I would suggest the following construct to fix the problem,
make your own per-thread stack of destructors that are callable
as functions and not macros.
It's not too hard to do.
Just use a pthread_key and pthread_once thingy to write a library
to do it, shouldn't take more than a hundred lines of code.
FWIW, OS X and QNX have the same set of macros, not sure about
other OSes.
-Alfred
>
> +#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?
> _______________________________________________
> freebsd-threads at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-threads
> To unsubscribe, send any mail to "freebsd-threads-unsubscribe at freebsd.org"
--
- Alfred Perlstein
More information about the freebsd-threads
mailing list