From owner-freebsd-threads@FreeBSD.ORG Wed Oct 8 05:12:16 2008 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A9F27106568F for ; Wed, 8 Oct 2008 05:12:16 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 99F7B8FC12 for ; Wed, 8 Oct 2008 05:12:16 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id 43AE91A3C36; Tue, 7 Oct 2008 21:54:47 -0700 (PDT) Date: Tue, 7 Oct 2008 21:54:47 -0700 From: Alfred Perlstein To: John Hein Message-ID: <20081008045447.GY36572@elvis.mu.org> References: <18668.10465.699531.162573@gromit.timing.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18668.10465.699531.162573@gromit.timing.com> User-Agent: Mutt/1.4.2.3i Cc: threads@freebsd.org Subject: Re: pthread_cleanup_push & pthread_cleanup_pop usage X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Oct 2008 05:12:16 -0000 * John Hein [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