gettimeofday day returning same value; possible bug or?

  • From: Chris <chris@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 24 Jul 2012 08:49:41 -0400

I'm using latest luajit from git compiled in 32-bit mode on a 64-bit Linux 3.4.5 kernel. The problem I'm seeing is that gettimeofday is returning exactly the same value all the time under some circumstances. Seems to possibly have something to do with tight loops.


I reduced the problem down to the following code:

------------------------------

local ffi = require'ffi'

ffi.cdef[[
   struct timeval {
      uint32_t sec;
      uint32_t usec;
   };

   int gettimeofday(struct timeval *restrict tp, void *restrict tzp);
]]

local tp = ffi.new("struct timeval")

function gettime()
   ffi.C.gettimeofday(tp, nil)
   --print("***", tp.sec, tp.usec)
   return tp.sec + (tp.usec / 1000000)
end

while true do
   print(gettime())
end

------------------------------

When run it will print the same unchanging value. If that commented-out print() call in gettime() is put in place then it starts working correctly. ???

--
Chris
http://luadev.com

Other related posts: