- 论坛徽章:
- 2
|
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
void * Thread(void *lpvoid)
{
while (1)
{
usleep(1000);
}
return lpvoid;
}
int main()
{
for (int i =0; i<50; i++)
{
pthread_t tid;
int eno = pthread_create (&tid, NULL, Thread, NULL);
if (eno)
{
printf("pthread_create err eno =%d\n",eno);
return 0;
}
}
Thread(NULL);
return 0;
}
这个代码在5.4系统上运行cpu 0
在6.1上运行就直接 10%
6系列redhat 内核改了啥,sleep占用高了那么多?
#include <pthread.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/timeb.h>
void wsleep(unsigned int MinSecond)
{
timeval t_timeval;
t_timeval.tv_sec = MinSecond / 1000;
t_timeval.tv_usec = MinSecond % 1000 * 1000 ;
select( 0, NULL, NULL, NULL, &t_timeval );
}
void * Thread(void *lpvoid)
{
while (1)
{
wsleep(1);
}
return lpvoid;
}
int main()
{
for (int i =0; i<50; i++)
{
pthread_t tid;
int eno = pthread_create (&tid, NULL, Thread, NULL);
if (eno)
{
printf("pthread_create err eno =%d\n",eno);
return 0;
}
}
Thread(NULL);
return 0;
}
换select也是一样都占用高 |
|