Created
December 17, 2015 22:21
-
-
Save Keruspe/eb48606f952ca3e3b8af to your computer and use it in GitHub Desktop.
stdin
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
diff --git a/foo.cc b/foo.cc | |
index 3c4f06c..51e8965 100644 | |
--- a/foo.cc | |
+++ b/foo.cc | |
@@ -33,11 +33,13 @@ Bank* Bank::global_instance = nullptr; | |
// Singleton instance of the bank | |
Bank* Bank::instance() { | |
// avoid multiple creations of a bank instance | |
- global_lock.lock(); | |
if (global_instance == nullptr) { | |
- global_instance = new Bank; | |
+ global_lock.lock(); | |
+ if (global_instance == nullptr) { | |
+ global_instance = new Bank; | |
+ } | |
+ global_lock.unlock(); | |
} | |
- global_lock.unlock(); | |
return global_instance; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment