Could you help me with the following interview question.
This Sleep(int seconds) function implements the following interface so that timers can be used:
- function
void CreateTimer(void (*func)(), int seconds) that its purpose is to create a timer - function
void StartTimers() that its purpose is to start all timers
Each running timer should be delayed for a few seconds, and then use the callback to call the function. Example:
CreateTimer(func1,3); CreateTimer(func2,7); CreateTimer(func3,10); StartTimers()
The following should happen:
Delay for 3 seconds, then calling function 1. Delay for 4 seconds, and then calling function 2. Delay for 3 seconds, and then calling function 3.
The question is how to implement such an interface?
Yakov source share