I recently developed a multi-thread module and used Linux time functions to find a bug, in multiple core servers, the time function will suddenly return more than 4000 seconds longer than the normal time. the Linux operating system we use is RedHatEnterpriseLinux5.0, and the kernel version is 2.6.18-8. below el5 is the test program # include & lt; iostream & gt; # include & lt; pthread. h & gt
I recently developed a module that uses multithreading and Linux time functions.
The result shows that a bug occurs. in multiple core servers, the time function will suddenly return more than 4000 seconds more than the normal time.
The Linux operating system we use is Red Hat Enterprise Linux 5.0, kernel version 2.6.18-8. el5
Below are the test procedures
# Include
# Include
# Include
Using namespace std;
Void * thr1_fun (void * param)
{
Time_t now, pre;
Time (& pre );
Time (& now );
For (;;)
{
If (time (& now) =-1)
Perror ("time ");
If (now-pre)> 5)
{
Std: cout <"thr?fun" <"now-pre" <now-pre <std: endl;
Pre = now;
}
}
}
Void * thr2_fun (void * param)
{
Time_t now, pre;
Time (& pre );
Time (& now );
For (;;)
{
If (time (& now) =-1)
Perror ("time ");
If (now-pre)> 5)
{
Std: cout <"thr2_fun" <"now-pre" <now-pre <std: endl;
Pre = now;
}
}
}
Int main ()
{
Pthread_t th1, 22;
Pthread_create (& th1, NULL, thr1_fun, NULL );
Pthread_create (& Th1, NULL, thr2_fun, NULL );
Pthread_join (th1, NULL );
Pthread_join (2nd, NULL );
Return 0;
}
The two threads keep running the time function to get the current time. The running result is occasionally a thread now-pre will print more than 4000 values, and no time function execution failure is found, then the thread that prints more than 4000 values will die.
After checking the information, it seems to be a kernel bug.
This bug is not found in Ubuntu 10.04 and kernel version 2.6.32.