Most operating systems have a way to "set an alarm" or "set a timer", which in the future will call the function of your user. In linux you would use alarm , in Windows you would use SetTimer .
These functions have limitations on what you can do in the called function, and you will almost certainly end up having multiple threads, although the thread may not call sleep , but some wait_for_event or a similar function.
Edit: However, using a stream with a stream that contains:
while(1) { sleep(required_time); function(); }
The problem is solved in a very direct way to solve the problem and makes it very easy to handle.
source share