pthread_cleanup_push & pthread_cleanup_pop usage

John Hein jhein at timing.com
Wed Oct 8 20:45:25 UTC 2008


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.
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.


More information about the freebsd-threads mailing list