关于多线程的一个问题,急求
redhat吧
全部回复
仅看楼主
level 1
阿嚏5342 楼主
急求啊,给跪了Orz~
2011年11月16日 16点11分 1
level 1
阿嚏5342 楼主
/* thread.c*/
#include <stdio.h>
#include <pthread.h>
void thread(void)
{
int i;
for(i=0;i<3;i++)
printf("This is a pthread.\n");
}
int main(int argc,char *argv[])
{
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);
}
2011年11月16日 16点11分 2
level 1
阿嚏5342 楼主
请问我编译之后:$gcc thread.c -lpthread -o thread
按理来说结果应该是:
得到如下结果:
This is the main process.
This is a pthread.
This is the main process.
This is the main process.
This is a pthread.
This is a pthread.
  再次运行,可能得到如下结果:
This is a pthread.
This is the main process.
This is a pthread.
This is the main process.
This is a pthread.
This is the main process.
每次应该是不一样的,可是我每次都是一样的
This is a pthread.
This is a pthread.
This is a pthread.
This is the main process.
This is the main process.
This is the main process.
每次都是这一个结果,请问这是怎么回事?

2011年11月16日 16点11分 3
level 1
阿嚏5342 楼主
如何在本程序中再添加一个进程?
2011年11月16日 16点11分 4
level 10
路过滚蛋%%%%%%%%
2012年08月20日 12点08分 5
level 10
哥,我知道了,你不会是每次都运行的是第一次gcc编译出的thread文件吧?
2012年08月20日 12点08分 6
2012年08月20日 13点08分
level 10
留个手印
2012年08月24日 08点08分 7
level 6
多线程吗?简单啊,分配好时间,位置,...
按次序循环来,和lun*jian没区别
2012年08月24日 14点08分 8
level 10
碉堡了 哈哈哈[勉强]
2012年09月01日 10点09分 9
1