Advertisement
Guest User

Untitled

a guest
May 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. struct Texture {
  2.   Texture(string const& path) { cout << "Texture loaded from " << path << endl; }
  3.  ~Texture() { cout<< "Texture destroyed" << endl; }
  4.  
  5.   static shared_ptr<Texture> load(string const& path) {
  6.   return make_shared<Texture>(path)
  7.   }
  8. };
  9.  
  10. // this functions will take a copy and increment the counter
  11. // using const& would not increment the ref-counter
  12. int doSomethingWithTexture(shared_ptr<Texture> const tex);
  13. int doSomethingElseWithTexture(shared_ptr<Texture> const tex);
  14.  
  15. void foo() {
  16.  shared_ptr<Texture> tex = Texture::load("textures/my_texture.png");
  17.  
  18.   thread(doSthWithTexture, tex).detach();
  19.   thread(doSthMoreWithTexture, tex).detach();
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement