|
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void thread(void)
{
int i;
for(i=0;i<3;i++)
printf("this is a pthread\n");
}
int main(void)
{
pthread_t id;
int i,ret;
ret=pthread_create(&id,NULL,(void *)thread,NULL);
if(ret!=0)
{
printf("create pthread error\n");
exit(1);
}
for(i=0;i<3;i++)
printf("this is the main process\n");
pthread_join(id,NULL);
return (0);
}
这个程序的结果为什么每次都是这样的?
this is the main process
this is the main process
this is the main process
this is a pthread
this is a pthread
this is a pthread
看了很多资料都不是这样的,请问是什么问题?我的系统是FC6,gcc 版本 4.1.1 20061011 (Red Hat 4.1.1-30) |
|