title: Modifying variables across thread function calls
body: <p>i am having a bit of a struggle with a mutli-threaded program i am trying to create. Its a pretty simple application im just creating in order to see how multi-threading works and so on :)</p>
  
  <p>okay so the thing is i have 2 threads and 1 variable, Thread1 is supposed to print the variable they have in common once every second or so(time does not really matter, its just an example) then while Thread1 sleeps for 1 second Thread2 comes in and edits its value to something completely different and the next time Thread1 runs its supposed to print the new value assigned by thread2 allthough this is not happening :/ what is happening is that Thread1 prints the default constructors value even tho it got changed, its kind of hard to explain in words so i have linked the simple example below, i am hoping someone can help me understand this. Btw i know i should be using a mutex or a critical section since im sharing a resources between the two, but since they never run at the same time and its just a simple example i just left it out.</p>
  
  <p>Main.cpp</p>
  
  <pre><code>int _tmain(int argc, _TCHAR* argv[])
  {
      Printer printer;
  
      std::thread thread1(&amp;Printer::SetMessage, printer, printer); //Sets the new value of "New Message"
      std::thread thread2(&amp;Printer::Print, printer, &amp;printer); //Prints the message using printf()
  
      while(true) {
          Sleep(5000); //i have a beakpoint here just to look at the variables once every 5 sec.
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Printer.cpp</p>
  
  <pre><code>void Printer::Print(Printer &amp;obj) {
      while(true) {
          printf(obj.Message.c_str());
          Sleep(1000);
      }
  }
  
  void Printer::SetMessage(Printer &amp;obj) {
      while(true) {
          Sleep(10000);
          obj.Message = "New Message";
      }
  }
  
  Printer::Printer(void){
      this-&gt;Message = "YOLO";
  }
  
  
  Printer::~Printer(void){}
  </code></pre>
  
  <p>so i simply want the value of Message to get updated in all other threads, i mean they are using the same object and changing the value in the same damn object, but why will it not stay changed between threads ??? im so confused :S i have only seen examples that do it in the same class, it got so much more complicated(in my brain) once i used multiple classes.</p>