A timer in a thread does not tally with the runtime of the program?

I am trying to create a game with a few threads running.
And i have create a thread to store the time since the process has run.

The code is:
1
2
3
4
5
6
void * clock_timer(void *arg){
    while(!menuExit){
        tstop = (double)clock()/CLOCKS_PER_SEC;
        ttime= tstop-tstart; /*ttime is how long your code run */
    }
}


But this clock does not sync with the reading i get when i timed my program.

It took 74.44 secnds.
Simulator Bot Exit
Program Destroyed.

real    0m45.061s
user    0m49.338s
sys     0m25.120s

Can anyone tell me how they implement a timer in a thread which can sync with the runtime of the program?

Under Linux (and possibly POSIX in general), clock() returns the amount of CPU time used by the process, not any value based on real time. Note that user+sys=74.458 s.
I can't seem to find any way to get the real value.
For measuring real time, there is clock_gettime:
http://linux.die.net/man/3/clock_gettime
I need some help or advice here:
My intention is clear:
a) I have a thread which does some object creation and i wish to store the time it has been created. Do I use sys, user or real time to store this value?

b) another timer thread will continue to run and if it checks and finds out that a object is outdated (by comparing the date), it will trigger another thread to do something else.

So what kind of time should i store?

thanks in advance
That's rather obvious, assuming you know the difference. So read this:
http://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1
Sorry, i have read that but i am still confused.
When we use usleep() and sleep(), are they related to REAL or USER time?
Real time... real time is just that, real time.
user+sys time is the time your program spends actually doing something (i.e. not sleeping).
Topic archived. No new replies allowed.