Skip to content

Commit c891bc2

Browse files
committed
clarify Reset
test=develop
1 parent 4f59690 commit c891bc2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

paddle/fluid/framework/threadpool.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ DEFINE_int32(dist_threadpool_size, 0,
2525

2626
namespace paddle {
2727
namespace framework {
28-
28+
std::mutex threadpool_mu;
2929
std::unique_ptr<ThreadPool> ThreadPool::threadpool_(nullptr);
3030
std::once_flag ThreadPool::init_flag_;
3131

3232
ThreadPool* ThreadPool::GetInstance() {
33+
std::lock_guard<std::mutex> l(threadpool_mu);
3334
std::call_once(init_flag_, &ThreadPool::Init);
3435
return threadpool_.get();
3536
}
3637

37-
void ThreadPool::Reset() {
38+
void ThreadPool::TestReset() {
39+
std::lock_guard<std::mutex> l(threadpool_mu);
3840
threadpool_.reset(nullptr);
3941
ThreadPool::Init();
4042
}

paddle/fluid/framework/threadpool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class ThreadPool {
5656
static ThreadPool* GetInstance();
5757

5858
// delete current thread pool and create a new one.
59-
static void Reset();
59+
// Only used by test cases to reset the threadpool.
60+
static void TestReset();
6061

6162
~ThreadPool();
6263

paddle/fluid/framework/threadpool_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ TEST(ThreadPool, ConcurrentRun) {
5252
for (auto& t : threads) {
5353
t.join();
5454
}
55-
framework::ThreadPool::Reset();
55+
framework::ThreadPool::TestReset();
5656
EXPECT_EQ(sum, ((n + 1) * n) / 2);
5757
}

0 commit comments

Comments
 (0)