Date: Wed, 8 Oct 2008 16:26:48 -0400 (EDT) From: Daniel Eischen <deischen@freebsd.org> To: Alfred Perlstein <alfred@freebsd.org> Cc: John Hein <jhein@timing.com>, freebsd-threads@freebsd.org Subject: Re: pthread_cleanup_push & pthread_cleanup_pop usage Message-ID: <Pine.GSO.4.64.0810081622530.6060@sea.ntplx.net> In-Reply-To: <20081008195324.GM36572@elvis.mu.org> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 8 Oct 2008, Alfred Perlstein wrote: > * John Hein <jhein@timing.com> [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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.0810081622530.6060>