- 論壇徽章:
- 0
|
11 int a = 10;
12 void *my1(void)
13 {
14 printf("i am one thread!\n");
15 sleep(3);
16 printf("thread leave!\n");
17 printf("The number of a:%d\n", a);
18 }
19
20 int main(void)
21 {
22 pthread_t id1;
23 pthread_create(&id1, NULL, (void *)my1,
NULL);
24 printf("back to the main funciton!\n");
25 printf("i am the main!\n");
26 return 0;
27 }
按照這里打印的結(jié)果看,好像線程也退出了。按照理論,
線程使用的是進(jìn)程的資源,進(jìn)程退出了,那么線程自然也
退出了,到底是他們兩個(gè)哪個(gè)先退出呢?線程睡眠了,然
后進(jìn)程執(zhí)行完了,線程不會(huì)醒來了???因?yàn)橘Y源被回收
了嗎??? |
|