I watched an article by Martin Thompson. This is an explanation of the false exchange.
http://mechanical-sympathy.blogspot.co.uk/2011/07/false-sharing.html
public final class FalseSharing implements Runnable { public final static int NUM_THREADS = 4;
The example demonstrates the slowdown caused by multiple threads, each other's invalid cache line, although each of them only updates only one variable.
Figure 1 above shows the problem of false exchange. The thread running on core 1 wants to update the variable X, and the thread on core 2 wants to update the variable Y. Unfortunately, these two hot variables are in the same cache line. Each thread will chase ownership of the cache line so that they can update it. If core 1 gains ownership, then the cache subsystem will need to revoke the corresponding cache line for core 2. When Core 2 gains ownership and updates it, core 1 will be declared invalid for its copy of the cache line. It will ping pong back and forth through the L3 cache, significantly affecting performance. The problem will be further exacerbated if the competing kernels are on different sockets and, in addition, you have to cross the socket interconnect.
My question is the following. If all updated variables are unstable, why does this addition cause an increase in performance? I understand that a volatile variable always writes and reads to main memory. Therefore, I would suggest that every write and read of any variable in this example will reset the current line of the kernel cache.
So, according to my understanding. If thread one invalidates thread two cacheline, it will not become apparant for thread two until it begins to read the value from its own cache line. The value that it reads is a mutable value, so this actually leads to the fact that the cache stub in any case leads to reading from main memory.
Where did I make a mistake in my understanding?
thanks
source share