Subj : Re: I write a multithread program with pthread, and meet a program To : comp.programming.threads From : David Butenhof Date : Fri Apr 22 2005 11:45 am Giancarlo Niccolai wrote: > David Butenhof wrote: > > >>That is, they may intend that you disable >>cancelability around any area of code that might do this; and while you >>can argue which makes most sense there's no objective authority to say >>they're wrong. > > Well, I never stated about correctness of one or the other possible > solution. I just stated that as long as cout uses write(), and unless c++ > makes a future statement about the contrary, cout will be a cancellation > point. Assuming that cout absolutely uses write() is arbitrary, and > probably should not be taken for granted; what I meant is just that IF cout > uses write(), and if C++ standard doesn't specify for the contrary, then > cout will be a cancellation point. That's only true if the C++ library in question doesn't disable cancellation around the write() call. Yes, you're right that if someone naively implements cout with no consideration at all of threads, it'll likely be a cancellation point. (Though not a guaranteed cancellation point, even so, since not every cout method will call write()... most streams are buffered.) MY point though was that you cannot assume that because cout (probably, sometimes/eventually) calls write() that is IS a cancellation point. It would be perfectly reasonable for a C++ library implementer to be aware of threads and to decide that cout operations should NOT be cancellation points, and to code accordingly. Neither POSIX nor ISO C++ says whether this is good or bad: it is entirely up to the judgement of the implementer. So unless you're coding for a specific implementation and you KNOW which decision the implementer made, your best strategy is to avoid making any assumptions. -- 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 .