Subj : Re: pthread function behavior in C++ program To : comp.programming.threads From : David Butenhof Date : Fri Jun 10 2005 10:58 am wij@seed.net.tw wrote: > Torsten Robitzki wrote: > >>... >>I used "NPTL C++ cancellation" to search on google and the >>results looks very promising. > > Now as understood, can I discard the use pthread_cleanup_push/pop in > C++ codes? POSIX specifically defines pthread_cleanup_push and pthread_cleanup_pop as a C construct that may not be appropriate for any other language binding. In particular, we expected (and would have liked to have required) that any language that implements real exceptions use the builtin mechanisms (e.g., C++ destructors and catch) instead of this C language hackery. HOWEVER, as POSIX does not actually provide any C++ language binding, it can't say either whether you need those operations or whether they're supported. That is, you cannot write portable C++ threaded code that either uses them or does not. If you do, it might not work on some platforms. If you DON'T, it might not work on some platforms. Similarly, as C++ says nothing about threads, you're left in a dark and sticky corner where any answer is entirely not just platform but release specific. If you expect to be working exclusively with a C++ implementation that exposes cancellation as exceptions, then you definitely should use the native C++ mechanisms instead of pthread_cleanup_push/pop. On some implementations (e.g., Tru64 UNIX and OpenVMS), the C macros won't even work correctly (or possibly at all) from C++ (they're based language extensions to integrate with the native platform exceptions that the C++ compiler doesn't support). Otherwise... you're best off completely avoiding cancellation in C++, if you can. If you can't, be really careful about determining what actually works, and why, on the platforms you need. -- Dave Butenhof, David.Butenhof@hp.com HP Utility Pricing software, POSIX thread consultant Manageability Solutions Lab (MSL), Hewlett-Packard Company 110 Spit Brook Road, ZK2/3-Q18, Nashua, NH 03062 .