‹ BackHN Continuity

Thread

Writing Efficient C++ Code (2013)

176 points · 161 comments · ibobev

  1. einpoklum · · focus · HN ↗
    > We know that the C++ keyword volatile is used to prevent a value from being optimized in a way that would allow the compiler to keep it in a processor register rather than fetching it from its original memory location each time.

    Actually, we don't know that. The meaning of volatile is rather subtle

    1. someonebaggy · · focus · HN ↗
      It does mean the compiler needs to treat loading and storing the value as a side effect - actually write a load instruction every time it's loaded in the source code. It's as if *X was a call to get_X() the compiler can't optimize around. However the next sentence which says you can use it for thread synchronization is wrong.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.