Is is possible to call a function at a specific time in C++? For example, I would like to launch function doIt() when number_of_elapsed_milliseconds_since_application_start = x.
A cross-platform solution would be ideal.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In pure C++ probably not, you will need some OS specific code. But you can use a platform-independent OS-wrapper, like Qt (although this could be a bit of an overkill for your quite simple problem).
EDIT: The simplest thing you could do, is actively blocking the program in a loop, that constantly polls the current time, until the deadline is reached, but that is probably not a very useful solution. So without threads or some event-driven timer (as every OS should have) you won’t get very far.