Propagate errors from set_threads instead of ignoring them

set_threads silently ignored failures from _add_thread_locked (e.g.
pthread_create failure) and _remove_thread_locked (e.g. at min_threads).
The caller had no way to know the pool was undersized or that shrinking
stopped early.

Stop on the first error and return it so callers can detect partial
completion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antonio S. Musumeci 2026-04-09 21:05:32 -04:00
parent 82e7980ec9
commit 055a2d4abe

View file

@ -745,10 +745,21 @@ ThreadPool::set_threads(const std::size_t count_)
current = _threads.size();
}
int rv = 0;
for(std::size_t i = current; i < count_; ++i)
_add_thread_locked({});
{
rv = _add_thread_locked({});
if(rv != 0)
return rv;
}
for(std::size_t i = count_; i < current; ++i)
_remove_thread_locked();
{
rv = _remove_thread_locked();
if(rv != 0)
return rv;
}
return 0;
}