2 ms·
If multiple threads are accessing two globals, two threads are not guaranteed to see changes in one or the other in the same order. This is called "sequential c
by WalterBright 14y ago
If multiple threads are accessing two globals, two threads are not guaranteed to see changes in one or the other in the same order. This is called "sequential consistency". The only way to get sequential consistency between threads is to insert memory barriers or use synchronization.
There is no way around this. Your statement that memory barriers could be skipped is exactly the source of the double checked locking bug. I know this is hard to understand, which is why it has tripped up a looong list of very smart people over the years.
David's article solves the problem by having one of the globals not be global at all, but thread local.
As for performance, David's article shows with benchmarks that his solution is a huge win.