Skip to content

Commit 3ba976f

Browse files
committed
Merge branch 'tim/fork_safety2' into 'master'
fix: Use non-racy thread count in stop_before_fork See merge request TankerHQ/tconcurrent!81
2 parents f13f35c + da9f5fa commit 3ba976f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/thread_pool.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ void thread_pool::stop(bool cancel_work)
150150

151151
void thread_pool::stop_before_fork()
152152
{
153-
assert(!_p->_num_threads_before_fork);
153+
// If called multiple times, just keep our saved state
154+
if (_p->_num_threads_before_fork.load())
155+
return;
156+
154157
// NOTE: We shouldn't use _num_running_threads as it has a delay
155158
_p->_num_threads_before_fork.store(_p->_threads.size());
156159

@@ -161,7 +164,12 @@ void thread_pool::stop_before_fork()
161164

162165
void thread_pool::resume_after_fork()
163166
{
167+
// If we weren't stopped, just keep running
168+
if (!_p->_threads.empty())
169+
return;
170+
164171
unsigned num_threads = _p->_num_threads_before_fork.load();
172+
165173
auto error_cb = std::move(_p->_error_cb);
166174
auto task_trace_handler_cb = std::move(_p->_task_trace_handler);
167175

0 commit comments

Comments
 (0)