4 ms·
Wouldn't globalFlag just be shared in a duplicated cache line between all cores until one of them modifies it?
by Rusky 11y ago
Wouldn't globalFlag just be shared in a duplicated cache line between all cores until one of them modifies it?
- scott_s 11y agoIf the code was: while (globalFlag) { ++someValue; } Then you'd probably be okay. But calling a function which does some lightweight but non-trivial work will interfere with your cache. When you come back from the stack frame for doSomeLightWork(), you're more likely to need to load globalFlag from memory. In a multithreaded application where you want to scale to dozens or even hundreds of threads, you have look at even global memory accesses as communication.
- Rusky 11y agoThat still doesn't sound like the cache line "bouncing around" any more than it would if a single-core app did the same work. There's no contention on it the way there would be on a shared mutable value, at least.
- scott_s 11y agoThere is still contention, but not as much. With, say, 8 threads it probably doesn't matter much. But with 128, it starts to matter.