SHARE
TWEET

What is wrong with this tiny piece of mutex code

a guest Feb 28th, 2012 9 Never
  1. // A Mutex allows threads mutually exclusive access to a resource.
  2. //-----------------------------------------------------------------------
  3.  
  4. class Mutex
  5. {
  6. private:
  7.     CRITICAL_SECTION m_mutex;
  8.  
  9. public:
  10.      Mutex() { InitializeCriticalSection(&m_mutex); }
  11.     ~Mutex() { DeleteCriticalSection(&m_mutex);     }
  12.  
  13.     void acquire() { EnterCriticalSection(&m_mutex); }
  14.     void release() { LeaveCriticalSection(&m_mutex); }
  15. };
  16.        
  17. InitializeCriticalSection Error: lpCriticalSection (0x000387d4) points to an invalid
  18.   memory location (0x00018984) Mutex::Mutex in lockmutex.h, line 29
  19.        
  20. struct Customer {
  21.     char * name;
  22. };
  23.  
  24. extern void greetCustomer(Customer* c);
  25.  
  26. class CheckoutLine {
  27.   private:
  28.     Customer m_customer;
  29.   public CheckoutLine() {
  30.     greetCustomer(&m_customer);
  31.   }
  32. };
RAW Paste Data
Top