No memory model

qznc qznc at web.de
Tue Oct 22 03:44:39 PDT 2013


On Tuesday, 22 October 2013 at 10:06:54 UTC, Moritz Maxeiner 
wrote:
> Sequential consistency would - afaik - mean, that executing the 
> threads of a nonsequential program in *any* interleaved order 
> on a single processor in the relative order the program 
> specifies for each thread internally would yield the same 
> results as executing it in a true non-sequential environment, 
> such as each thread being executed by one processor without any 
> necessary interleaving.
>
> Again, as far as I understand the concept, it you truly had 
> sequential consistency, you would not need atomic operations, 
> but I don't think marking a variable as "shared" would really 
> provide that, because then the compiler would need to inject 
> locks for every shared variable and use them for all 
> read/writes of that variable.

You are a little bit off. Sequential consistency (SC) does 
require the compiler to insert locking.

Initially: x = y = 0

  thread 1     | thread 2
  x = 1;       | if (y == 2)
  y = 2;       |   assert (x == 1)

SC guarantees that the assert succeed or is not executed due to 
the if-statement. Without SC, the assignments of thread 1 might 
be seen in a different order from thread 2, which means there is 
a point in time, where y==2 && x==0.


More information about the Digitalmars-d mailing list