
October 27th, 2004, 04:57 PM
|
|
Contributing User
|
|
Join Date: Oct 2004
Location: Toronto
Posts: 58

Time spent in forums: 10 h 48 m 42 sec
Reputation Power: 4
|
|
ok i've got to this far, basically now i declared a global variable "clock" and accumulate it whenever it passes 1ms, but i've got error message......
Quote: #include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 1
double clock=0;
void *clockwait(void *threadid)
{
while(1) {
struct timeval first, second, last; // declare the timeval variables
gettimeofday(&first, NULL); // get the time at the first time
gettimeofday(&second, NULL); // get the time at the second time
last.tv_usec=second.tv_usec-first.tv_usec; // get the difference of the second and the first time collections
clock = clock + last.tv_usec;
}
}
int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc, t;
printf("Creating thread %d\n", t);
rc = pthread_create(&threads[t], NULL, clockwait, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
sleep(10);
printf("clock is %d", clock);
} |
but i got this error message
edithello.c:15: `clock' redeclared as different kind of symbol
/usr/include/iso/time_iso.h:85: previous declaration of `clock'
what's wrong with my code?
|