Last active
September 18, 2018 21:24
-
-
Save George3d6/2543ee34739baab7013907028cd5d9cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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