Skip to content

Commit

Permalink
ensure singleton::get thread safe construct instance (#658)
Browse files Browse the repository at this point in the history
* ensure singleton::get thread safe construct instance

* fix singleton return reference

Co-authored-by: xuweiqi <[email protected]>
  • Loading branch information
2 people authored and ttl10101 committed Feb 7, 2024
1 parent 2633cf8 commit 56ea302
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions tools/library/src/singleton.cu
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ namespace library {

/////////////////////////////////////////////////////////////////////////////////////////////////

static std::unique_ptr<Singleton> instance;

/////////////////////////////////////////////////////////////////////////////////////////////////

Singleton::Singleton() {

manifest.initialize();
Expand All @@ -54,10 +50,8 @@ Singleton::Singleton() {
}

Singleton const & Singleton::get() {
if (!instance.get()) {
instance.reset(new Singleton);
}
return *instance.get();
static Singleton instance;
return instance;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 56ea302

Please sign in to comment.