作者conjure0 (有夢最美 希望相隨)
看板LinuxDev
標題[問題]請問以下的程式用LINUX泡為何獨不到FORK()和WAIT()啊
時間Mon Apr 13 20:34:31 2009
#include <pthread.h>
#include <stdio.h>
int value=0;
void *runner(void *param);/* the thread*/
int main(int argc, char *argv[])
{
int pid;
pthread_t tid;
pthread_attr_t attr;
pid=fork();
if (pid==0){/*child process*/
pthread_attr_init(&attr);
pthread_create(&tid,&attr,runner,NULL);
pthread_join(&tid,NULL);
printf("CHILD: value = %d",value);/*LINE c*/
}
else if (pid>0){/*parent process*/
wait(NULL);
printf("PARENT: value = %d" , value);/*LINE P*/
}
}
void *runner(void *param){
value = 5;
pthread_exit(0);
}
麻煩高手回答THX~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.241.43
推 dakiyo:沒有引入標頭檔? 04/14 00:38
→ conjure0:為何pthread_create沒辦法讀到啊? 04/14 16:21
推 richardhesid:錯別字太多 04/14 16:23
推 aguan:gcc -lpthread, pthread_join參數錯了 04/15 02:18