fork(1) download
  1. // stub mutex_t: implement this for your operating system
  2. struct mutex_t
  3. {
  4. void Acquire() {}
  5. void Release() {}
  6. };
  7.  
  8. struct LockGuard
  9. {
  10. LockGuard(mutex_t& mutex) : _ref(mutex)
  11. {
  12. _ref.Acquire(); // TODO operating system specific
  13. };
  14.  
  15. ~LockGuard()
  16. {
  17. _ref.Release(); // TODO operating system specific
  18. }
  19. private:
  20. LockGuard(const LockGuard&); // or use c++0x ` = delete`
  21.  
  22. mutex_t& _ref;
  23. };
  24.  
  25. int main()
  26. {
  27. mutex_t mtx;
  28.  
  29. {
  30. LockGuard lock(mtx);
  31. // LockGuard copy(lock); // ERROR: constructor private
  32. // lock = LockGuard(mtx);// ERROR: no default assignment operator
  33. }
  34.  
  35. }
  36.  
Success #stdin #stdout 0s 2720KB
stdin
Standard input is empty
stdout
Standard output is empty