wait() and wait_for(timeout) suspend an HPX thread for a short time while
other work exists, so that a waiter with a high priority doesn't starve the
threads it waits for on a single worker. wait_for(stop_token, timeout), which
hpx::local::termination_detection(stop_token, timeout) uses, still yielded:
a high priority waiter on one worker kept running until its timeout, and
returned false although the threads it waited for would have finished at
once. It now uses the same wait, which checks the stop token on each round.
The test termination_detection_priority waits from a high priority thread on
one worker; it hit the 10 s timeout before this change.
Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
#8189 made
threadmanager::wait()andwait_for(timeout)suspend an HPX thread for 100 microseconds between the checks while other work exists, so that a waiter with a high priority doesn't starve the threads it waits for on a single worker.wait_for(stop_token, timeout), whichhpx::local::termination_detection(stop_token, timeout)uses, was left yielding: a high priority waiter on one worker kept being picked again until its timeout passed, and then returnedfalsealthough the threads it waited for would have finished at once.This change routes
wait_for(stop_token, timeout)through the same wait as the other two. The wait now takes a callable that is checked on each round and stops the wait (returningfalse) once stop was requested on the token, as before.The new test
termination_detection_prioritywaits with a stop token from a high priority thread on one worker. Before this change it hit its 10 s timeout and failed; with it, it passes in about 30-50 ms.Testing: GCC 12 and Clang 23 (warnings as errors),
termination_detection_prioritywith 1 and 2 workers andtermination_detectionwith 4 workers pass with both compilers; without the fix the new test fails with 1 worker.