1

Is there any built-in functionality in c++ to run task at scheduled time? (Some thing like cron?) Or have I to implement it myself?

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

The closest you can do is to wait on a mutex or other synchonization primitive for a specified period of time.

"Release" the mutex (or fire a condition variable, etc) if the app is told to shut down (always a good plan), and if it times out, otherwise run the task.

Note that there are no realtime guarantees -- wait in C++ waits "at least that long". Basically, if the system is busy, tough.

This can be done in a thread, naturally, so whatever main functionality (message pump or whatever) isn't bothered by it.

You can also sleep for a specified period of time, but programs should always have an abort possibility, and sleeping doesn't provide it.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524