I'm currently struggling to make the following thing:
I'd like to create a thread that performs a specific (very quick) action every second, but which can also be stopped at any moment during the waiting time from the parent thread.
How can I achieve this with maximum efficiency? I've tried so far:
- Waiting 50 times for a duration of 20 milliseconds, checking at each iteration the value of an
AtomicBoolto check if the thread should be stopped, and if set exit properly ;
- Setting up a
Condvar, but as the docs state the amount of time is not precise, plus it's not designed for that usage.
Any idea on this?