Subj : Re: Memory visibility and the C compiler... ( a bit long ) To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Sat Jan 15 2005 02:06 pm "SenderX" writes: >> The compiler is a part of the Pthreads implementation, and must >> refrain from doing things that would violate the Pthreads >> semantics. > > Does the compiler actually look for calls to all pthread_xxx sync > functions, and prevents aggressive optimization of function > call/shared&local variable ordering across them? The opposite: it looks for calls to functions which are safe to have aggresive optimizations performed around them, and performs them only in these cases. If a compiler doesn't know what a given function does, it must assume that it might call synchronization functions somewhere. > My library uses externally assembled routines for basically everything that > requires precise ordering: stacks, queues, eventcounts's, ect.... So, an > aggressive "link-time" optimizer still might be able to mess things up? No. Inline asm will work too if the asm is appropriately annotated. In the case of gcc I think it must be specified that it clobbers memory (to prevent caching variables in registers across the asm) and it must be marked as volatile (to prevent reordering, and prevent deletion even if the outputs of asm are not used). info '(gcc)Extended Asm' -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .