title: Thread safe access to member variable
body: <p>So I have a class which spawns a thread with the class object as parameter. Then in the thread I call a member function. I use Critical_Sections for synchronizing.</p>
  
  <p>So would that implementation be thread safe? Because only the member is thread safe and not the class object. </p>
  
  <pre><code>    class TestThread : public CThread
      {
      public:
          virtual DWORD Work(void* pData) // Thread function
          {
              while (true)
              {
                  if (Closing())
                  {
                      printf("Closing thread");
                      return 0;
                  }
  
                  Lock();   //EnterCritical
                  threadSafeVar++;
                  UnLock(); //LeaveCritical
  
              }
          }
  
          int GetCounter()
          {
              int tmp;
              Lock();   //EnterCritical
              tmp = threadSafeVar;
              UnLock(); //LeaveCritical
  
              return tmp;
          }
  
      private:
          int threadSafeVar;
      };
  
  .
  .
  .
  
      TestThread thr;
  
      thr.Run();
  
      while (true)
      {
          printf("%d\n",thr.GetCounter());
      }
  </code></pre>