halayli / lthread

lthread, a multicore enabled coroutine library written in C
Other
814 stars 82 forks source link

Incorrect time calculation in scheduler on 32 bit systems #29

Open wisd0me opened 10 years ago

wisd0me commented 10 years ago

There is a bug in integer addition in _lthread_usec_now(): signed long time_t overflows. The return statement must look like this:

/* _lthread_usec_now(): */
    return (uint64_t) t1.tv_sec * 1000000 + t1.tv_usec;

Bug shows itself as follows - after some point in time lthread functions with timeouts start trashing the cpu, in my case it was lthread_read(). I've found this after I was unable to recover seconds from sched->birth on my 32bit box.

wisd0me commented 9 years ago

I must notice, that to confirm & fix this bug, only a few things required:

  1. gdb
  2. 32 bit box
  3. change one line of code

Which of them is causing the trouble?