title: PThread Crashes Within Class in C++
body: <p>So I am pretty new to threading in general and have been experimenting with pthreads for the past couple of weeks. I have created a class that has a threaded function within itself. It works fine, until I tried to set a class property (an integer) to a value. </p>
  
  <p>.h file:</p>
  
  <pre><code>#ifndef TESTCLASS_H
  #define TESTCLASS_H
  
  #include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  using namespace std;
  
  class testClass
  {
      public:
          testClass();
          HANDLE h;
          static DWORD WINAPI mythread(LPVOID param);
          int mytestint;
          void printstuffs();
          void startThread();
  };
  
  #endif // TESTCLASS_H
  </code></pre>
  
  <p>.cpp file</p>
  
  <pre><code>#include "testClass.h"
  
  testClass::testClass()
  {
      cout &lt;&lt; "Created class" &lt;&lt; endl;
  }
  DWORD WINAPI testClass::mythread(LPVOID param)
  {
      cout &lt;&lt; "In thread" &lt;&lt; endl;
      testClass* This = (testClass*)param;
  
      cout &lt;&lt; "Calling class function" &lt;&lt; endl;
      This-&gt;printstuffs();
  
      cout &lt;&lt; "Thread is done" &lt;&lt; endl;
  
      return NULL;
  }
  void testClass::printstuffs()
  {
      cout &lt;&lt; "In class function " &lt;&lt; endl;
      mytestint = 42; // &lt;- crashes here
      cout &lt;&lt; "Test Int = " &lt;&lt; mytestint &lt;&lt; endl;
  }
  void testClass::startThread()
  {
      h = CreateThread(NULL, 0, mythread, (LPVOID)0, 0, NULL);
      cout &lt;&lt; "Thread started" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>So why does it crash when I call <code>mytestint = 42;</code> ?</p>