看板 Grad-ProbAsk 關於我們 聯絡資訊
int value = 0; void *runner(void *param); int main(in argc, char *argv[]) { int pid; phread_t tid; pthread_arrt_t attr; pid = fork() if(pid == 0){//child pthread_attr_init(&attr); pthread_create(&tid,&attr,runner,NULL); pthread_join(tid,NULL); printf("%d\n",value); //line C }else if(pid>0){ //parent wait(NULL); printf("%d\n",value);//line P } } void *runner(void *param) { value = 5; pthread_exit(0); } -------------------------------------------------- 這題答案line C是5 line P是0 請問有可能出現line P=5的答案嗎? fork()以後應該是把value的值複製一份到子process的記憶體位置吧? 所以子process不管如何更改自己的value值應該都無法影響父process的 value 我這樣的觀念是正確的嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.230.55.239 ※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1426068880.A.62D.html
galapous: y 03/12 00:52