
_ReadWriteBarrier stops the compiler from reordering. Going to a non-intrinsic InterlockedCompareExchange will also have this effect, but it might be possible to achieve it in another (cheaper) compiler-specific way; __asm__ ( :::"memory" ) is the GCC equivalent. Borland may already not reorder across a volatile read; this needs to be tested.
Totally agreed. The easiest change to make mingw and Borland non-broken was to use ICE, but it is definitely overkill if there's a cheaper way.
All that's need here is a compiler barrier; I couldn't find an equivalent in the Borland docs this morning, but that doesn't mean there isn't one. Does __asm__ ( :::"memory" ) work on mingw? If so, I'll use that rather than ICE for mingw.
FWIW, Intel V10 on Windows seems not to implement _ReadWriteBarrier neither (at least we get linker errors there as well). Regards Hartmut