I'm calling the following from the main() function, and also in other created threads. While, it works fine in the created threads, it returns a large junk value in my main().
long getTimeMilliSecs()
{
struct timeval tempTime;
gettimeofday(&tempTime, NULL);
long retVal = 1000000*tempTime.tv_sec + tempTime.tv_usec;
return retVal;
}
Using Linux Ubuntu with gcc. Does anyone know the reason for this peculiar behaviour? Thank You!
Using it in this fashion:
main()
{
:
emuTime = getTimeMilliSecs();
}
Thread side code:
long time1 = getTimeMilliSecs();
printf("time1: %ld emuTime: %ld\n", time1, emuTime);
OUTPUT:
time1: 9006806 emuTime: 1380680868658357
Similar way of calling in threads.
From comments: Updated! emuTime
is also of type long
.
long emuTime; emuTime = getTimeMilliSecs();
– harshalizee Oct 02 '13 at 02:28