Bruno Haible <[EMAIL PROTECTED]> writes: > 1) The practical reason is that while developing libsigsegv, I noticed that > C does not have the notion of a "barrier": In code like this: > > set_up_datastructures(); > /* HERE I would like a barrier */ > signal(sig,my_signal_handler); > > I would like a barrier to ensure that all memory stores of > set_up_datastructures() have been performed before the signal handler > is activated. __asm__("" : : : "memory"); is not portable (works only with > GCC). Calls to an empty global function are optimized away by GCC 4. [...]
Is it safe to use an external function that is only defined in a separate translation unit? For example, to define an empty function in a source file all by itself, then use a call to it as a barrier. This introduces a barrier in the common situations that I know about, although there is the small overhead of a call-and-return sequence. (Are there compilers or linkers that do inter-module optimization?) -- "Term, holidays, term, holidays, till we leave school, and then work, work, work till we die." C. S. Lewis