title: Is there a way to flush the entire CPU cache related to a program?
body: <p>On <code>x86-64</code> platforms, the <code>CLFLUSH</code> assembly instruction allows to flush the cache line corresponding to a given address. Instead of flushing the cache related to a specific address, would there be a way to flush the entire cache (either the cache related to the program being executed, or the entire cache), for example by making it full of dummy contents (or any other approach I would not be aware of):</p>
  
  <ul>
  <li>using only standard C++17?</li>
  <li>using standard C++17 and compiler intrinsics if necessary?</li>
  </ul>
  
  <p>What would be the contents of the following function: (the function should work regardless of compiler optimizations)?</p>
  
  <pre><code>void flush_cache() 
  {
      // Contents
  }
  </code></pre>