Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class Volume
  2. {
  3. atomic<int> _width;
  4. atomic<int> _height;
  5. atomic<int> _depth;
  6. public:
  7. int computeValue() {return (_width*_height*_depth);}
  8. void SetInternals(int w, int h, int d) {_height=h;_width=w;_depth=d;}
  9. };
  10.  
  11. f->SetInternals(42, 100, 200);
  12.  
  13. int something_important = f->computeValue();
  14.  
  15. class Volume
  16. {
  17. int _width;
  18. int _height;
  19. int _depth;
  20. mutex _mutex;
  21. public:
  22. int computeValue() {
  23. lock_guard<mutex> lck(_mutex);
  24. int result = _width*_height*_depth);
  25. return result;
  26. }
  27. void SetInternals(int w, int h, int d) {
  28. lock_guard<mutex> lck(_mutex);
  29. _height=h;_width=w;_depth=d;
  30. }
  31. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement