clarify Reset

test=develop
release/1.1
Xin Pan 7 years ago
parent 4f59690b4c
commit c891bc22f5

@ -25,16 +25,18 @@ DEFINE_int32(dist_threadpool_size, 0,
namespace paddle {
namespace framework {
std::mutex threadpool_mu;
std::unique_ptr<ThreadPool> ThreadPool::threadpool_(nullptr);
std::once_flag ThreadPool::init_flag_;
ThreadPool* ThreadPool::GetInstance() {
std::lock_guard<std::mutex> l(threadpool_mu);
std::call_once(init_flag_, &ThreadPool::Init);
return threadpool_.get();
}
void ThreadPool::Reset() {
void ThreadPool::TestReset() {
std::lock_guard<std::mutex> l(threadpool_mu);
threadpool_.reset(nullptr);
ThreadPool::Init();
}

@ -56,7 +56,8 @@ class ThreadPool {
static ThreadPool* GetInstance();
// 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();

@ -52,6 +52,6 @@ TEST(ThreadPool, ConcurrentRun) {
for (auto& t : threads) {
t.join();
}
framework::ThreadPool::Reset();
framework::ThreadPool::TestReset();
EXPECT_EQ(sum, ((n + 1) * n) / 2);
}

Loading…
Cancel
Save