1

I have read Intel document about memory orderings on x64: http://www.multicoreinfo.com/research/papers/2008/damp08-intel64.pdf .They says that locked instructions cause full barriers which makes processors to see e.g. updates in specified order. But there is nothing about visibility caused by barriers. Does barriers cause that other processors will see updates of variables immediately or maybe updates will propagate to other processors only in specified order but with not specified time?

E.g.

Thread1:

flag = true;
MemoryBarrier();

Thread 2:

MemoryBarrier();
tmp = flag;

Does thread 2 will always flag=true if Thread 1 will execute its code before Thread 2?

rnd
  • 123
  • 7

1 Answers1

3

The barriers guarantee that other processors will see updates in the specified order, but not when that happens.

Which brings the follow-up question, how do you define "immediately" in a multiprocessor system [1], or how do you ensure that Thread 1 executes before Thread 2? In this case, one answer would be that Thread 1 uses an atomic instruction such as xchg to do the store to the flag variable, and then Thread 2 spins on the flag, and proceeds when it notices that the value changes (due to the way the x86 memory model works, Thread 2 can spin using normal load instructions, it is sufficient that the store is done with an atomic)

[1] One can think of it in terms of relativistic physics, each observer (thread) sees events through its own "light cone". Hence one must abandon concepts such as a single universal time for all observers.

janneb
  • 36,249
  • 2
  • 81
  • 97