title: How to get result of a thread in C++
body: <p>I have written a function which It is doing the Fibonacci calculation. I wanted to start and execute it with CreateThread as a thread. Finally, I want to save the result of the thread (the Fibonacci) and show it in the console. What is the problem with my code? It doesn't work properly. It starts the thread, but I don't know how should I store the result of the thread and show it.</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;iostream&gt;
  
  DWORD WINAPI Fibonacci(LPVOID arg_repeat) {
      DWORD dwValue = *(int*)arg_repeat;
  
      if (dwValue &lt; 3)
          return 1;
  
      return Fibonacci((int*)dwValue - 1) + Fibonacci((int*)dwValue - 2);
  }
  
  auto main(int argc, const char* argv[]) -&gt; decltype(0) {
      DWORD dwFibonacciValue;
      std::cout &lt;&lt; "Fibonacci Value: ";
      std::cin &gt;&gt; dwFibonacciValue;
  
      DWORD dwThreadId;
      HANDLE hThreading = CreateThread(NULL, 0, Fibonacci, &amp;dwFibonacciValue, NULL, &amp;dwThreadId);
      WaitForSingleObject(hThreading, INFINITE);
  
      std::cout &lt;&lt; "Fibonacci Result: " &lt;&lt; dwResult &lt;&lt; std::endl;
      CloseHandle(hThreading);
  
      return 0;
  }
  </code></pre>