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

  免費注冊 查看新帖 |

Chinaunix

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

[函數(shù)] localtime_r在多線程環(huán)境下出現(xiàn)死鎖 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2010-06-24 13:56 |只看該作者 |倒序瀏覽
#include <pthread.h>
#include <time.h>

void test(char *arg)
{
    pthread_detach(pthread_self());

    struct tm now;
    time_t datetime;

    while (1) {
            time (&datetime);
            localtime_r(&datetime, &now);
            usleep(10);
    }
}

int main()
{
        int rt;
        int tid[7];

        pthread_create(&tid[0], NULL, test, NULL);
        pthread_create(&tid[1], NULL, test, NULL);
        pthread_create(&tid[2], NULL, test, NULL);
        pthread_create(&tid[3], NULL, test, NULL);
        pthread_create(&tid[4], NULL, test, NULL);
        pthread_create(&tid[5], NULL, test, NULL);
        pthread_create(&tid[6], NULL, test, NULL);

        usleep(3000);

        pthread_cancel(tid[0]);
        pthread_cancel(tid[1]);
        pthread_cancel(tid[2]);
        pthread_cancel(tid[3]);

        sleep(1000000);
}

運行大概2秒左右,使用dbx得到如下結果:
(dbx) thread
thread  state-k     wchan            state-u    k-tid mode held scope function
$t1     wait      0xf1000610124a19b0 running  16978061   k   no   sys  nsleep            
$t2     zomb                         terminated 13464059   k   no   sys  pthread_exit      
>$t3     run                          blocked  21594345   k   no   sys  _global_lock_common
$t4     wait      0x000000011000abb8 blocked  21369113   k   no   sys  _rec_mutex_lock   
$t5     wait      0x000000011000abb8 blocked  17006771   k   no   sys  _rec_mutex_lock   
$t6     wait      0x000000011000abb8 blocked  21324271   k   no   sys  _rec_mutex_lock   
$t7     wait      0x000000011000abb8 blocked  21598443   k   no   sys  _rec_mutex_lock   
$t8     wait      0x000000011000abb8 blocked  21332225   k   no   sys  _rec_mutex_lock   

使用truss命令檢查,進程一直停在sleep。沒有任何localtime_r的函數(shù)調用。

我的環(huán)境是AIX6.1,目前沒有其他的環(huán)境,無法進行測試,能幫忙解釋一下原因嗎?謝謝!

論壇徽章:
0
2 [報告]
發(fā)表于 2010-06-24 14:07 |只看該作者
18         localtime_r(&datetime, &now);
19         printf("tid:%u\n", pthread_self());
20         usleep(10);


我的測試,一直在輸出:
tid:3023997840
tid:3034487696
tid:3034487696
tid:3044977552
tid:3023997840
tid:3034487696
tid:3044977552
tid:3023997840
tid:3034487696
tid:3044977552
tid:3023997840
tid:3034487696
tid:3023997840
tid:3044977552
tid:3034487696
tid:3023997840
tid:3044977552
tid:3034487696
tid:3034487696
tid:3044977552
tid:3023997840
tid:3034487696
tid:3044977552

論壇徽章:
0
3 [報告]
發(fā)表于 2010-06-24 14:08 |只看該作者
沒有死鎖

論壇徽章:
0
4 [報告]
發(fā)表于 2010-06-24 14:16 |只看該作者
樓上兩位的測試環(huán)境都是AIX6.1嘛?

論壇徽章:
0
5 [報告]
發(fā)表于 2010-06-25 14:20 |只看該作者
usleep有bug產(chǎn)生死鎖,我在centos上碰到過,沒法最后用select代替了usleep

論壇徽章:
0
6 [報告]
發(fā)表于 2010-06-25 16:40 |只看該作者
本帖最后由 hankgpg 于 2010-06-25 17:10 編輯

樓主也配叫"wzabcd1234"?  我認識的wzabcd1234 是個非常漂亮的mm, 185cm, 體重160....
您需要登錄后才可以回帖 登錄 | 注冊

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP