Timer in milliseconds

Hello,

I want to create a timer which ticks after I run my program.
this timer should call one of my functions in 10 or 100 milliseconds.
I have some info about time.h but I think it is not compatible to my requirements. So if someone gives me a clue what I should do first hand, I ll be glad.

Thank you.
You're trying to measure how long something takes to execute? In that case, ctime will work perfectly. Create your own macro for clock ticks per millisecond, create a clock object for your start, one for your end, get the number of clock ticks since your program started upon starting of your timer, then get the number of clock ticks since your program started upon the ending of your timer, and take the difference.

If you're trying to set a delay, then ctime would work but it's a waste of resources. Use (on UNIX) usleep(milliseconds) or (on Windows) Sleep(milliseconds).

-Albatross
Last edited on
I am trying to put a timer to my code which triggers a function I already coded in some interval(10 ms or 100 ms). Your approach seems good but I need to optimize it as well so I search some and find out ACE Frame work has some timers. In my project I use ACE as well. I am reading to how to implement one of these timers to my code. If I feel your approach is better I ll do that:)

thanks for advice

Omar
In this thread, I wrote a mock-up of a timed callback in C++. Unfortunately, the time was not very accurate. Consider my approach but with a different underlying timer:
http://www.cplusplus.com/forum/beginner/23636/

Note that my approach is extensible, as apposed to the other suggested solutions.
Last edited on
are you on a POSIX box.
you can use the threaded realtime clock.

google timer_create.
there don't seem to be any good examples anywhere.

you will need:
-lrt -lpthread

I have a really ropey example i was playing about with one time, if you like.

forgot to mention:

it invokes a callback function.
Last edited on
I tried to use ACE framework's timer queue I wrote the code but I got an error like:

/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/bin/ld: cannot find -lACE
collect2: ld returned 1 exit status


is there anyone who has an idea about this error?

is this about a missing file or a mistake i made on code?

thanks for advice.
yes, the linker cannot find the library.
if it's not in a standard place you need to tell it where.
have you set the LD_LIBRARY_PATH? as here:

http://smart-robotics.sourceforge.net/aceSmartSoft/install-linux.php

of interest, try ldconfig -p
Topic archived. No new replies allowed.