title: C++ multithreading problem - is mutex the only way?
body: <p>I have a counter variable which will be accessed by multiple threads which will increment/decrement it. It should not be updated by multiple threads at the same time.</p>
  
  <p>I know that you can create a mutex object which has to be obtained before the variable in question can be changed. A critical section in this case is not appropriate because there are more than 1 function which can change the variable in question.</p>
  
  <p>Is there another I can do this without using the mutex? Using a mutex does have a performance penalty (see <a href="http://www.codeguru.com/forum/showthread.php?t=333192" rel="nofollow noreferrer">http://www.codeguru.com/forum/showthread.php?t=333192</a>). I believe that in Java, there is a key word you can use in the variable declaration to accomplish that (is it called "synchronized"?), but is there such a thing in C++ at all?</p>
  
  <p>I know that volatile is not the keyword I am looking for.</p>
  
  <p>Thank you very much.</p>