title: Does setting a variable equal to itself actually execute in C++?
body: <p>I am working on creating oblivious graph algorithms, which basically hides the memory access pattern of an algorithm. The memory is assumed to be encrypted, but can be monitored by an attacker. The processor is assumed to be in the cloud, be secure, and have its own cache.</p>
  
  <p>It is known that the access pattern of a graph could reveal information about that graph.</p>
  
  <p>In order to make an algorithm oblivious, it is necessary to add dummy work to the algorithm. Such work includes reading and writing data, but in such a way as to not cause the results of the algorithm to be changed (such changes would make the algorithm useless, of course).</p>
  
  <p>It is necessary that the dummy work be on the graph itself, otherwise the attacker would be able to trace which work is real and which work is fake.</p>
  
  <p>Of course, adding dummy work creates slowdowns. Thus, as a lean solution, I would like to assign a variable to itself. This would create a read and a write to a location without actually changing anything. My question is, do compilers actually execute this code (it seems to in gdb, but is that just because it is a debugger)? I'm using gcc, but it would be best if the algorithm could be compiled with different compilers and still remain oblivious.</p>
  
  <p>The alternative to setting a variable equal to itself would be to use an if statement: check if the variable equals some value, and then set the variable to that value inside the if statement. If possible, I would like to avoid if statements because they slow things down.</p>
  
  <p>Lastly, this algorithm is multithreaded. If a global variable is set equal to itself, is it necessary to put a mutex lock on it? Such locks will of course slow things down, so I would like to avoid them if possible.</p>