Replace usleep with nanosleep in monitor thread

usleep is POSIX-obsolescent and its behavior on signal interruption is
under-specified. Replace with nanosleep which is the current POSIX
standard and has well-defined EINTR semantics. Pre-compute the
timespec once outside the loop since the interval is constant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antonio S. Musumeci 2026-04-09 21:58:43 -04:00
parent f8ac649e6f
commit d166418675

View file

@ -481,9 +481,14 @@ ThreadPool::monitor_routine(void *arg_)
constexpr int decline_threshold = 2;
int warmup_samples = 0;
const struct timespec sleep_ts = {
static_cast<time_t>(interval / 1000000),
static_cast<long>((interval % 1000000) * 1000)
};
while(!btp->_stop.load(std::memory_order_acquire))
{
usleep(interval);
nanosleep(&sleep_ts,NULL);
if(btp->_stop.load(std::memory_order_acquire))
break;