usleep函数的参数类型为unsigned int

https://linux.die.net/man/3/usleep


(1)usleep((0xffffff*1000));




由于传入的参数溢出被截断,


0xffffff*1000只运行了3892秒。



(2)   usleep((0xffffffff));

传入的参数刚好是usleep可接受的最大值,


0xffffffff运行了4295秒。比0xffffff*1000运行


的时间还要长





#include <stdio.h>  
#include <time.h>  
#include <stdlib.h>  
#include <string.h>  
#include <unistd.h>

typedef unsigned long   U32;

void func()
{
   U32 a ,b;
    a = time(NULL);
    printf("====%lu===",a );
   //usleep((0xffffff*1000));
   usleep((0xffffffff));
   b = time(NULL);
   printf("====%lu===",b);
   printf("====%lu===",b-a);
   
}

  
int main()  
{  
    func();
}


Logo

更多推荐