From owner-freebsd-threads@FreeBSD.ORG Thu Oct 9 01:24:09 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 CE8B2106568C for ; Thu, 9 Oct 2008 01:24:09 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id BD4E28FC24; Thu, 9 Oct 2008 01:24:09 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from apple.my.domain (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m991O8XT009288; Thu, 9 Oct 2008 01:24:09 GMT (envelope-from davidxu@freebsd.org) Message-ID: <48ED5DA4.9060803@freebsd.org> Date: Thu, 09 Oct 2008 09:25:56 +0800 From: David Xu User-Agent: Thunderbird 2.0.0.9 (X11/20080612) MIME-Version: 1.0 To: John Hein References: <18668.10465.699531.162573@gromit.timing.com> In-Reply-To: <18668.10465.699531.162573@gromit.timing.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: Thu, 09 Oct 2008 01:24:09 -0000 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