提交 c891bc22 编写于 作者: X Xin Pan

clarify Reset

test=develop
上级 4f59690b
...@@ -25,16 +25,18 @@ DEFINE_int32(dist_threadpool_size, 0, ...@@ -25,16 +25,18 @@ DEFINE_int32(dist_threadpool_size, 0,
namespace paddle { namespace paddle {
namespace framework { namespace framework {
std::mutex threadpool_mu;
std::unique_ptr<ThreadPool> ThreadPool::threadpool_(nullptr); std::unique_ptr<ThreadPool> ThreadPool::threadpool_(nullptr);
std::once_flag ThreadPool::init_flag_; std::once_flag ThreadPool::init_flag_;
ThreadPool* ThreadPool::GetInstance() { ThreadPool* ThreadPool::GetInstance() {
std::lock_guard<std::mutex> l(threadpool_mu);
std::call_once(init_flag_, &ThreadPool::Init); std::call_once(init_flag_, &ThreadPool::Init);
return threadpool_.get(); return threadpool_.get();
} }
void ThreadPool::Reset() { void ThreadPool::TestReset() {
std::lock_guard<std::mutex> l(threadpool_mu);
threadpool_.reset(nullptr); threadpool_.reset(nullptr);
ThreadPool::Init(); ThreadPool::Init();
} }
......
...@@ -56,7 +56,8 @@ class ThreadPool { ...@@ -56,7 +56,8 @@ class ThreadPool {
static ThreadPool* GetInstance(); static ThreadPool* GetInstance();
// delete current thread pool and create a new one. // delete current thread pool and create a new one.
static void Reset(); // Only used by test cases to reset the threadpool.
static void TestReset();
~ThreadPool(); ~ThreadPool();
......
...@@ -52,6 +52,6 @@ TEST(ThreadPool, ConcurrentRun) { ...@@ -52,6 +52,6 @@ TEST(ThreadPool, ConcurrentRun) {
for (auto& t : threads) { for (auto& t : threads) {
t.join(); t.join();
} }
framework::ThreadPool::Reset(); framework::ThreadPool::TestReset();
EXPECT_EQ(sum, ((n + 1) * n) / 2); EXPECT_EQ(sum, ((n + 1) * n) / 2);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册