Date: Tue, 7 Oct 2008 21:54:47 -0700 From: Alfred Perlstein <alfred@freebsd.org> To: John Hein <jhein@timing.com> Cc: threads@freebsd.org Subject: Re: pthread_cleanup_push & pthread_cleanup_pop usage Message-ID: <20081008045447.GY36572@elvis.mu.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 <jhein@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@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-threads > To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org" -- - Alfred Perlstein
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20081008045447.GY36572>