From 062d5a56b401162ebd0232e42135c87177ad68ec Mon Sep 17 00:00:00 2001 From: gongweibao Date: Mon, 11 Jun 2018 09:42:54 +0800 Subject: [PATCH] Add comments to a singleton. (#11333) --- paddle/fluid/framework/data_type.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/paddle/fluid/framework/data_type.cc b/paddle/fluid/framework/data_type.cc index b6b93cf42..60382faff 100644 --- a/paddle/fluid/framework/data_type.cc +++ b/paddle/fluid/framework/data_type.cc @@ -28,6 +28,9 @@ struct DataTypeMap { }; static DataTypeMap* InitDataTypeMap(); +// C++11 removes the need for manual locking. Concurrent execution shall wait if +// a static local variable is already being initialized. +// https://stackoverflow.com/questions/11711920/how-to-implement-multithread-safe-singleton-in-c11-without-using-mutex static DataTypeMap& gDataTypeMap() { static DataTypeMap* g_data_type_map_ = InitDataTypeMap(); return *g_data_type_map_; -- GitLab