From 4627c0c14704a6518b4331f70acb1399a8d0733b Mon Sep 17 00:00:00 2001 From: gongweibao Date: Sun, 10 Jun 2018 12:43:30 +0000 Subject: [PATCH 1/2] add comment to singleton --- paddle/fluid/framework/data_type.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/paddle/fluid/framework/data_type.cc b/paddle/fluid/framework/data_type.cc index b6b93cf422a60..5226d10a18b81 100644 --- a/paddle/fluid/framework/data_type.cc +++ b/paddle/fluid/framework/data_type.cc @@ -28,6 +28,10 @@ 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_; From f74734d36a5250d3614e0d33e69263ac674953a6 Mon Sep 17 00:00:00 2001 From: gongweibao Date: Sun, 10 Jun 2018 13:03:58 +0000 Subject: [PATCH 2/2] fix style --- paddle/fluid/framework/data_type.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/framework/data_type.cc b/paddle/fluid/framework/data_type.cc index 5226d10a18b81..60382faffb8e5 100644 --- a/paddle/fluid/framework/data_type.cc +++ b/paddle/fluid/framework/data_type.cc @@ -28,9 +28,8 @@ 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. +// 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();