亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3315 | 回復(fù): 3
打印 上一主題 下一主題

pthread編程-線程退出后為什么不會(huì)釋放資源 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2009-09-07 11:41 |只看該作者 |倒序?yàn)g覽
本帖最后由 wdove 于 2012-05-09 16:19 編輯

線程函數(shù)里什么都不干,pthread_join后線程占用的空間還是不釋放。各位老大指教

tmp$ gcc a.c -lpthread
tmp$ ./a.out &
main process
[1] 3817
開始沒有進(jìn)入進(jìn)程時(shí),只有2M內(nèi)存
tmp$ ps aux|grep -i a.out
b17931    3817  0.0  0.0   1728   392 pts/2    S    11:37   0:00 ./a.out
b17931    3819  0.0  0.0   3068   788 pts/2    R+   11:37   0:00 grep -i a.out
tmp$ thread fn1
線程執(zhí)行完后,pthread_join了,應(yīng)該釋放內(nèi)存,但是居然一直占用10M
tmp$ ps aux|grep -i a.out
3817  0.0  0.0  10056   460 pts/2    S    11:37   0:00 ./a.out
3822  0.0  0.0   3068   788 pts/2    R+   11:37   0:00 grep -i a.out
tmp$

程序代碼:

  1. #include <stdio.h>
  2. #include <pthread.h>

  3. void* fn1(void* arg)
  4. {
  5.     printf("thread fn1\n");
  6.     return NULL;
  7. }


  8. int main()
  9. {
  10.     pthread_t tid;
  11.     printf("main process\n");

  12.     sleep(20);

  13.     pthread_create(&tid, NULL, fn1, NULL);
  14.     pthread_join(tid, NULL);

  15.     sleep(500);

  16.     return 0;
  17. }
復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2009-09-07 14:02 |只看該作者

回復(fù) #1 wdove 的帖子

你調(diào)用線程之后,不僅僅是運(yùn)行了你線程函數(shù)里面的代碼吧?
應(yīng)該還有很多位線程運(yùn)行提供服務(wù)的后臺(tái)資源沒有釋放。

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2009-09-07 18:43 |只看該作者
#include <stdio.h>
#include <pthread.h>

void* fn1(void* arg)
{
    printf("thread fn1\n");
    pthread_exit(0);
}


int main()
{
    pthread_t tid;
    printf("main process\n");

    sleep(20);

    pthread_create(&tid, NULL, fn1, NULL);
    pthread_join(tid, NULL);

    sleep(500);

    return 0;
}

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2009-09-08 11:05 |只看該作者
找到了,是因?yàn)閠hread棧大小默認(rèn)是8192K,所以增了8M,可以用pthread_attr_setstacksize()去設(shè)置棧大小。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP