Skip to content

Instantly share code, notes, and snippets.

@George3d6
Last active September 18, 2018 21:24
Show Gist options
  • Save George3d6/2543ee34739baab7013907028cd5d9cf to your computer and use it in GitHub Desktop.
Save George3d6/2543ee34739baab7013907028cd5d9cf to your computer and use it in GitHub Desktop.
//Return a shared pointer, meaning this resource is shared
//Someone else might be using the underlying object
shared_ptr get_widget();
int use_widget() {
auto widget_ptr = get_widget();
//Thus we shall take the thread-safe approach and lock the widget before using it
widget_ptr->lock_widget_mutex();
if(widget_ptr->get_status() == 42)
widget_ptr->trigger_event();
widget_ptr->unlock_widget_mutex();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment