title: How to use a single object in multiple threads?
body: <p>I want to use a single object in multiple threads using c++. I know from java that threads share all variables, but it seems that in c++ it is different.</p>
  
  <p>I have the following structure to store the date</p>
  
  <pre><code>Class Flow: has multiple integers
  Class UE: has a list&lt;Flow*&gt;
  Class FlowTable: has a map&lt;int,UE*&gt;
  </code></pre>
  
  <p>Now have two threads(Objects: InOutReader and OutInReader), each of them has a FlowTable* and shall read and/or insert data to the FlowTable.</p>
  
  <p>in the main() of my starter I call new FlowTable(), create the threaded objects and give the FlowTable* to them using a setter. But in the end it looks like that the two threads work with different FlowTable objects.</p>
  
  <pre><code>class InOutReader{
  public:
  
  start(){
  
  while(true){
  //read data from somewhere(tap-interface1)
  //extract address from ip packet and tcp/udp header etc
  Flow* myflow = new Flow(IPsrc,IPdest);
  this-&gt;myflowTable-&gt;insertFlow(myflow);
  }
  }
  }
  
  class OutInReader{
  public:
  start(){
  while(true){
  //read data from somewhere(tap-interface1)
  //extract address from ip packet and tcp/udp header etc
  Flow* myflow = new Flow(IPsrc,IPdest);
  this-&gt;myflowTable-&gt;existsFlow(myflow);// should return true if a flow with the same data was inserted before
  }
  }
  }
  </code></pre>
  
  <p>main programm
      FlowTable* myflowTable;</p>
  
  <pre><code>startThreadOne(){
  InOutReader ior = InOutReader();
  ior.setFlowTable(myFlowTable);
  ior.start();
  }
  
  startThreadtwo(){
  InOutReader oir = InOutReader();
  oir.setFlowTable(myFlowTable);
  oir.start();
  }
  
  void main(){
  myFlowTable = new FlowTable();
  std::thread t1 = std::thread(startThreadOne);
  std::thread t2 = std::thread(startThreadtwo);
  
  t1.join();
  t2.join();
  }
  </code></pre>
  
  <p>What I have to do to use the same FlowTable Object in multiple threads?</p>