Re: Curious global variable bug? Bad assumptions on my part?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eljay Love-Jensen wrote:
Adding volatile to the g_counter tells the compiler not to optimize away
access to the variable, as the variable can change "at any time".

That may sound like just the thing for multi-threaded access to the same
variable -- but it's not sufficient.

Even though the compiler is no longer going to optimize away access to the
variable, the hardware can still effectively isolate the two threads from
one another, such that neither thread is aware that the g_counter variable
has changed.

Why?  Because each thread could run with the variable stored in separate
caches.

Huh? I thought SMP hardware is required to be responsible for cache syncing in such an instance...

--
Matthew
Thus sang the fat lady...


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux