- 论坛徽章:
- 0
|
下面是测试程序的代码, 这段代码在hp平台下无法输出rt()函数中的信息,如果在main()函数中使用pthread_join()则会陷入死循环, 估计是系统时间片的问题,不知哪位高手可以帮忙解决.
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
void*
rt(void* data)
{
struct timeval to;
while(1)
{
to.tv_sec = 20;
to.tv_usec = 0;
if (select(0, 0, 0, 0, &to) == 0)
printf(\"Thread is running.\\n\");
}
return NULL;
}
void main()
{
struct timeval mto;
mto.tv_sec = 60;
mto.tv_usec = 0;
pthread_t pid;
pthread_create(&pid, 0, rt,0);
select(0, 0, 0, 0, &mto);
printf(\"main program is finished.\\n\");
} |
|