Performing an action after regular time intervals.

Hi, I want to do a thing I never did before. I want to read number from a file after regular time intervals (20 milliseconds for example. )

I am running a runtime programme so I cannot use Sleep() as it makes the screen blank . I am working on an OpenGL code. I have my file reading syntax ready so only thing remains is putting a time interval between reading two numbers !

Can anybody give me a suggestion as to where can I start.

Thank you in advance
Rohit
Hi, one way to do it is to use multiple threads, I don't know if your already doing that.
Though that's a bit overboard just to tell the time. The easier option which I would recommend is using timers.
See http://www.cplusplus.com/reference/clibrary/ctime/difftime/ and you can work it how you want. It's really useful, and uses a good example, I've used it loads. Just take two separate times and compare. It should do the job, though I'm not entirely sure of your program setup, you may find it hard to implement, though in many cases it's pretty straight forward.
Last edited on
you can use a timer

http://opengroup.org/onlinepubs/007908799/xsh/timer_create.html

opengl? if you are using some framework like X, GTK or QT there are timers
available, also input methods for files to invoke a callback when there is data to be read.
that's where I would look first.
for instance in X I have used this:

http://www.it.freebsd.org/pub/Unix/XFree86/WWW/htdocs/current/XtRemoveInput.3.html

most graphical toolkits have something similar.
Last edited on
Topic archived. No new replies allowed.