Skip to content

Commit c907ec7

Browse files
committed
ai min: ThPoolBack
1 parent 1b39ede commit c907ec7

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/thread/ThPoolBack.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ThPoolBack::ThPoolBack(size_t aMaxThread)
2525
thPool_.reserve(aMaxThread); // not construct any thread
2626
for (size_t i = 0; i < aMaxThread; ++i)
2727
{
28-
thread th([this]() noexcept
28+
thPool_.emplace_back([this]() noexcept
2929
{ // thread main()
3030
for (;;)
3131
{
@@ -47,22 +47,13 @@ ThPoolBack::ThPoolBack(size_t aMaxThread)
4747

4848
// - thread can continue when task() throw
4949
// - other excepts (eg bad_alloc) are rare & hard-recover
50-
try { task(); }
51-
catch(...) {} // packaged_task already saved exception in its future
50+
task(); // packaged_task saves exception in its future
5251

5352
// no lock so can only use MT_safe part in "this"
5453
this->mt_nDoneFut_.fetch_add(1, std::memory_order_relaxed); // fastest +1
5554
mt_pingMainTH(); // notify mainTH 1 task done
5655
}
5756
}); // thread main()
58-
if (th.joinable()) {
59-
thPool_.emplace_back(move(th));
60-
}
61-
else { // ut can't cover this branch
62-
// - rare
63-
// - throw is safer than just log(=hide)
64-
throw runtime_error("(ThPoolBack) failed to construct some thread!!!");
65-
}
6657
} // for-loop to create threads
6758
} catch(...) { // ut can't cover this branch; rare but safer
6859
clean_();

0 commit comments

Comments
 (0)