Retry nanosleep on EINTR in monitor thread

nanosleep returns -1 with errno EINTR when interrupted by a signal.
The remaining time was discarded (second arg was NULL), causing the
monitor to wake early and sample a shortened interval. This produced
artificially low throughput numbers that corrupted the EMA and could
trigger unnecessary scale-down decisions.

Loop on EINTR using the remaining time output parameter so the full
sample interval is always honored. Also check _stop on each retry
so the monitor exits promptly during shutdown.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antonio S. Musumeci 2026-04-09 23:30:13 -04:00
parent beb6961769
commit b150f2c685

View file

@ -498,7 +498,14 @@ ThreadPool::monitor_routine(void *arg_)
while(!btp->_stop.load(std::memory_order_acquire))
{
nanosleep(&sleep_ts,NULL);
{
struct timespec remaining = sleep_ts;
while(nanosleep(&remaining,&remaining) == -1 && errno == EINTR)
{
if(btp->_stop.load(std::memory_order_acquire))
break;
}
}
if(btp->_stop.load(std::memory_order_acquire))
break;