title: C++ how to end a thread called in a while loop?
body: <p>I have two functions that run simultaneously thanks to thread, both functions write text in two separates files.</p>
  
  <pre><code>void Function1() {
      //Blablabla do stuff
      File1 &lt;&lt; My stuff &lt;&lt; std::endl;
  }
  
  void Function2() {
      //Blablabla do other stuff
      File2 &lt;&lt; other stuff &lt;&lt; std::endl;
  }
  
  int main {
     File1.open();
     File2.open();
     while (true){
          std::thread Th1(Function1);
          std::thread Th2(Function2);
  
          Th1.join();                
          Th2.join();     
          // I want to end my thread here         
          if (0x01 &amp; GetAsyncKeyState('Q') != 0) {
              // What to put here to safely end function 1 and function 2 ?
              }
          }
      File1.close();
      File2.close();
      return 0;
  }
  </code></pre>
  
  <p>How to end the thread to be able to close the files ? I am new to the use of the class Thread.</p>