[lkml]   [2002]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Subjectgettimeofday problem

    I am writing a small piece of code that use the gettimeofday routine and
    I have noticed a very strange behaviour. If I call the routine two times
    in sequence I expect that the second value is greater than or equal to
    the first one, but it is not true.

    please check the following code.

    Sometimes happen that the string "Strange Behaviour" is printed with
    kernel 2.4.18.

    I tried to find in the Linux Archive patches to solve this problem, but
    I didn't find anything (there are emails that talk about gettimeofday,
    but probably they do not answer to my questions).

    The same thing happen in Java using the System.currentTimeMillis() routine.

    #include <fstream.h>
    #include <sys/time.h>

    // this routine calculate the current time returning its value in long
    long format.
    long long currentTimeMillis() {
    long long t;
    struct timeval tv;

    gettimeofday(&tv, 0);

    t = tv.tv_sec;
    t = (t *1000) + (tv.tv_usec/1000);

    return t;

    void main() {
    for (;;) {
    long long a = currentTimeMillis();
    long long b = currentTimeMillis();

    if (a>b) {
    cout << "Strange Behaviour" << endl;

    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 13:27    [W:0.024 / U:113.544 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site