Skip to content

Instantly share code, notes, and snippets.

@njlr
Created May 25, 2017 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save njlr/feae1dabdc19e97a4675ff4e47266b0f to your computer and use it in GitHub Desktop.
Save njlr/feae1dabdc19e97a4675ff4e47266b0f to your computer and use it in GitHub Desktop.
struct Texture {
  Texture(string const& path) { cout << "Texture loaded from " << path << endl; }
 ~Texture() { cout<< "Texture destroyed" << endl; }
 
  static shared_ptr<Texture> load(string const& path) {
  return make_shared<Texture>(path)
  }
};
int doSomethingWithTexture(shared_ptr<Texture> const tex);
int doSomethingElseWithTexture(shared_ptr<Texture> const tex);
int main() {
 shared_ptr<Texture> tex = Texture::load("textures/my_texture.png");
 
  thread(doSthWithTexture, tex).detach(); 
  thread(doSthMoreWithTexture, tex).detach(); 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment