Subj : Re: Is the following code MT-safe? To : comp.programming.threads From : David Hopwood Date : Fri Jan 07 2005 04:09 am tom_usenet wrote: > if the following code is in a signal handler [in a multithreaded > program]: > > //i and j are volatile > ++i + ++j; //main program code might see them increment in either > //order, since there is no sequence point > > ++i, ++j; //program is guaranted to see i increment before j. You're mistaken, other threads are not guaranteed to see i increment before j. Remember, the C standard on its own doesn't apply *at all* to multithreaded code. For this to be well-defined in C+POSIX, POSIX would have to specify how the statements about volatile in the C standard apply to memory as seen by other threads. It doesn't, so those statements are meaningless in such cases. Indeed, real-world implementations will violate this 'guarantee'. -- David Hopwood .