This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

What is wrong with this tiny piece of mutex code

By: a guest on Feb 28th, 2012  |  syntax: None  |  size: 0.78 KB  |  views: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. };
clone this paste RAW Paste Data