4 ms·
If the code was: while (globalFlag) { ++someValue; } Then you'd probably be okay. But calling a function which does some lightweight but non-t
by scott_s 11y ago
If 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.