|
一个示范的多线程程序,就在主函数里面创建两个线程,然后在两个线程里面是死循环,一直打印。但是一运行就一直重复打印下面的东西:
Allocation of length 2097152 from process 19 failed
Buffer memory: 368kB
Free pages: 4724kB ( 0kB HighMem)
Zone:DMA freepages: 0kB min: 0kB low: 0kB high: 0kB
Zone:Normal freepages: 4724kB min: 80kB low: 160kB high: 240kB
Zone:HighMem freepages: 0kB min: 0kB low: 0kB high: 0kB
( Active: 135, inactive: 43, free: 1181 )
= 0kB)
1*4kB 0*8kB 1*16kB 1*32kB 1*64kB 0*128kB 0*256kB 1*512kB 0*1024kB 2*2048kB = 4724kB)
= 0kB)
是什么原因啊?
程序我在linux底下编译而且运行过,没有一点问题。
但是在uclinux底下就这样了。
程序:
#include<stdio.h>
#include<pthread.h>
#include<time.h>
#include<errno.h>
void thread1(void)
{int i=0;
for(i=0;i<6;i++)
{printf("\tthread1\n");
if(i==2)
pthread_exit(0);
usleep(5000);
}
}
void thread2(void)
{
int i;
while(1){
for(i=0;i<3;i++)
printf("thread2\n");
usleep(5000);}
pthread_exit(0);
}
int main(void)
{
pthread_t id1,id2;
int ret;
pthread_attr_t attr;
//init thread
pthread_attr_init(&attr);
pthread_attr_setscope(&attr,PTHREAD_SCOPE_SYSTEM);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
//create thread
ret=pthread_create(&id1,&attr,(void *) thread1,NULL);
if(ret!=0){
printf("create pthread1 error\n");
exit(1);
}
ret=pthread_create(&id2,NULL,(void *) thread2,NULL);
if(ret!=0){printf("create pthread2 error\n");
exit(1);
}
pthread_join(id1,NULL);
pthread_join(id2,NULL);
return 0;
} |
|