Sleeping flow and waiting on a handle with a timeout are basically the same under the covers. I would suggest that timers are essentially implemented through sleep, so there aren't many differences. In other words, you could simplify your code by waiting on the timeout descriptor in one loop and checking why the wait (available data or timeout) has been freed up, instead of doing separate wait and wait cycles. Slightly more efficient than independent circuits.
Ideally, you will not use sleep at all and simply envy the data generation code to correctly raise the event that your consumption code expects, with a long timeout for processing when the event source has left.
If the data is external, for example, on a socket or other input device, then you can usually set a descriptor so that you can expect the data to become available - there is no need to poll in this case, since the event will always be signaled when the data is ready for consumption.
source share