title: C++, how to share data between processes or threads
body: <p>I have a program which runs two different operations and i'd like to share variables between them.</p>
  
  <p>At the moment, i'm using threads instead of fork processes but i'm having problems in sharing variables even if I declared them as volatile.</p>
  
  <p>I tried with boost doing:</p>
  
  <pre><code>boost::thread collisions_thread2(boost::bind(function_thread2);
  </code></pre>
  
  <p>by declaring the shared variables as volatile, but it seems that function_thread2() function is not able to see changes on the shared variables.</p>
  
  <p>What i'd like to do is something like:</p>
  
  <pre><code>thread1:
  
  while(true){
  //..do somet stuff
  check variable1
  }
  
  thread2:
  
  while(true){
  do some other stuff
  check and write on variable1
  }
  </code></pre>
  
  <p>Can you suggest me a tutorial or a method to easily share variable between threads?
  May be boost library can be useful in this case?
  Do you think it's better to use fork()?</p>
  
  <p>I know that i have to use mutex in order to avoid critical situations, but i never used it.</p>