• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            大龍的博客

            常用鏈接

            統計

            最新評論

            使用pthread_cond_timedwait把一個線程作為一個定時器使用. --- 轉

             
            [c-sharp] view plaincopy
            1. #include <pthread.h>  
            2. #include <stdio.h>  
            3. #include <unistd.h>  
            4. #include <stdlib.h>  
            5. void * Proc(void * arg)  
            6. {  
            7.    pthread_cond_t cond;  
            8.    pthread_mutex_t mutex;  
            9.   
            10.     pthread_mutex_init(&mutex,NULL);  
            11.     pthread_cond_init(&cond,NULL);  
            12.   
            13.    timespec to;  
            14.   
            15.     int i = 0;  
            16.     pthread_mutex_lock(&mutex);  
            17.     to.tv_sec = time(NULL) + 3;  
            18.     to.tv_nsec = 0;  
            19.     while (i < 5)   
            20.     {  
            21.   
            22.         int err = pthread_cond_timedwait(&cond, &mutex, &to);  
            23.         if (err == ETIMEDOUT)   
            24.         {  
            25.              printf("time out %d: dispatch something.../n",i);  
            26.          i++;  
            27.         }  
            28.   
            29.     }  
            30.   
            31.      pthread_mutex_unlock(&mutex);  
            32.   
            33.   
            34. }  
            35. int main()  
            36. {      
            37.     pthread_t pid;  
            38.     int i=0;  
            39.     printf("create thread.../n");  
            40.     pthread_create(&pid,0,Proc,0);  
            41.     pthread_join(pid,NULL);  
            42.     sleep(1);  
            43.     printf("Succeed exit!/n");  

            posted on 2013-02-17 19:42 大龍 閱讀(5213) 評論(0)  編輯 收藏 引用

            深夜久久AAAAA级毛片免费看| 久久精品亚洲精品国产色婷| 欧美亚洲另类久久综合| 久久99精品久久久久久秒播| 欧美亚洲国产精品久久高清| 精品免费久久久久久久| 久久精品无码av| 久久水蜜桃亚洲av无码精品麻豆| 国产精品一区二区久久精品无码 | 国产精品久久一区二区三区| 欧美激情精品久久久久久| 一本久久知道综合久久| 国内精品久久久久久久影视麻豆| 7777精品久久久大香线蕉| 狠狠久久综合伊人不卡| 久久国产乱子伦免费精品| 思思久久99热只有频精品66| 91精品国产9l久久久久| 亚洲级αV无码毛片久久精品| 精品久久久久久无码人妻热| 国产精品视频久久久| 国产亚洲精久久久久久无码77777| 国产精品99久久不卡| 国产美女久久精品香蕉69| 久久99热这里只有精品国产| 久久亚洲精品无码观看不卡| 久久电影网2021| 国产日产久久高清欧美一区| 亚洲欧美久久久久9999| 伊人色综合久久天天人守人婷| 国产精品激情综合久久| 国内精品久久久久影院网站| 国产福利电影一区二区三区久久久久成人精品综合 | 精品无码久久久久久久久久| 久久亚洲国产欧洲精品一| 国产91色综合久久免费| 国产99久久精品一区二区| 99久久99这里只有免费费精品| 婷婷久久久亚洲欧洲日产国码AV| 亚洲国产精品无码久久久蜜芽| 亚洲精品无码成人片久久|