"Variable Caching Fix with Membar"
private static void LoopThreadStart() { while (!cancelLoop) { ++counter; Thread.MemoryBarrier(); } }
Code snippet taken from
"Common Multithreading Mistakes in C# - III: Unsafe Assumptions"
.