I am currently working on shared memory I want to calculate the time taken for the thread1 to write and thread2 to read from shared memory. For this I used:
clock_gettime(CLOCK_REALTIME,&start)
in thread1, and after reading from thread2. I again called:
clock_gettime(CLOCK_REALTIME,&end)
The time taken for reading and writing can be calculated from:
dt = (double) (end.tv_sec - start.tv_sec) +
((double) (end.tv_nsec - start.tv_nsec) / 1000000000.0);
But every time I run the program I am getting different results. What am I doing wrong?