Re: GTimers - do they need initialization ?



On Wed, Mar 17, 2010 at 11:37:04AM -0000, John Emmas wrote:
> The following code is giving me strange results when I build it using MSVC++
> and link to the binaries for glib-win32  (I've tried VC++8 and also falling
> back to VC++6)
>
> #include <glib/gtimer.h>
> int main (int argc, char* argv[])
> {
> gulong microseconds;
> int count;
>
>     GTimer* pTimer = g_timer_new ();
>
>     do {
>          g_timer_elapsed (pTimer, &microseconds);
>          count = (int) microseconds;
>
>          printf ("Time elapsed = %d\n", count);
>
>          g_usleep (1000000);
>     } while (microseconds < 10000000);
>
>      return 0;
> }

The microseconds parameter contains the fractional part hence it can
never reach 10000000.  Also, it's rather useless, the retrun double
value contains all the information.

Please see the documentation.

> At first, I assumed that running in the debugger
> might be upsetting the timer so I decided to look at the output from just
> running the program normally.  But if I run the program normally I just get
> this repeated ad infinitum:-
>
> Time elapsed = 0
> Time elapsed = 0
> Time elapsed = 0
> Time elapsed = 0
> Time elapsed = 0
> Time elapsed = 0
>
> I didn't call 'g_timer_start()' because the manual says that it gets called
> automatically by g_timer_new().  However, even if I call it, I still see the
> same output.

What exactly does g_usleep() on MS Windows?  I have no idea.  The
documentation says

    g_usleep() may have limited precision, depending on hardware and
    operating system; don't rely on the exact length of the sleep.

which may mean anything.  It works on Unix, of course, but there's
real usleep() available.

Yeti



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]