From owner-freebsd-threads@FreeBSD.ORG Wed Oct 8 20:40:31 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 74F22106564A; Wed, 8 Oct 2008 20:40:31 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id 2DB898FC14; Wed, 8 Oct 2008 20:40:31 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.3/8.14.3/NETPLEX) with ESMTP id m98KQmwP002461; Wed, 8 Oct 2008 16:26:48 -0400 (EDT) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.0 (mail.netplex.net [204.213.176.10]); Wed, 08 Oct 2008 16:26:49 -0400 (EDT) Date: Wed, 8 Oct 2008 16:26:48 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Alfred Perlstein In-Reply-To: <20081008195324.GM36572@elvis.mu.org> Message-ID: References: <18668.10465.699531.162573@gromit.timing.com> <200810081409.31822.jhb@freebsd.org> <18669.3729.459915.769388@gromit.timing.com> <20081008195324.GM36572@elvis.mu.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: John Hein , freebsd-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 Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Oct 2008 20:40:31 -0000 On Wed, 8 Oct 2008, Alfred Perlstein wrote: > * John Hein [081008 12:48] wrote: >> John Baldwin wrote at 14:09 -0400 on Oct 8, 2008: >> > Don't Do That (tm). The spec explicitly states that they can be defined as >> > macros and that code using it needs to put them in the same block. >> >> Thanks for the responses. I like deischen's response best to work >> around the problem short term, but I suspect that's not very portable. It's probably more portable than you think. The library calls really need to be there so they can be linked to from non-C languages. >> And as jhb describes using it outside the same block violates the >> spirit of intended use. >> >> Note that the example I gave (pop off the cleanup stack in a catch >> block) is not our only "violation". We also push in one function and >> either never [explicitly] pop or possibly pop in another function. >> >> So that leaves me wondering about possible techniques for cleanup on >> thread cancellation or exit. Alfred touched on one method, and I see >> that pthread_key_create takes an optional destructor, so that sounds >> like a possible avenue to explore. > > I'm positive that you'll have a solution given my starting point > within a few hours. :) > > All the cpp_cleanup_push() needs to do is to: > > pthread_once() -> set up the pthread_key and destructor as you said. > then pthread_getspecific to get the stack > if no stack, make one and set it. > then push your cleanup function. > > good luck, -- DE