Flow control

I'm writing a simple app that, quite honestly, would probably be better done in another language, but I figured I would take the opportunity to learn a little C++ at the same time.

It isn't meant to do a whole lot, just some lightweight file maintenance on a semi-regular basis. I'm shooting for hourly.

So, for example, if it does its thing around noon, and I don't want it to do anything again until around 1:00, could anyone suggest a way accomplish that as efficiently (CPU wise) as possible?

I can think of a few ways to do it, but they all seem ridiculously taxing, cpu wise. In fact, I was poking around in the time.h reference on this site and saw some sample code that included a wait function, which was one of the first ideas I came up with, so I went ahead and compiled it and sure enough, it ran at 50% CPU (100% of one of my cores).

Is there a better way?
For Windows there's Sleep() (milliseconds); for UNIX, there's usleep() (microseconds).

Basically, all you need to do is wait some time and check the time. This is so fast, you can do it once per second and the CPU usage will be undetectable.
Last edited on
Awesome! Thank you for the prompt response.
Topic archived. No new replies allowed.