• <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>
            Cpper
            C/C++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            線程 Joining and Detaching相關(guān)函數(shù)4個
            pthread_joinpthread_detach

            pthread_attr_setdetachstate

            pthread_attr_getdetachstate
            Joining的作用
            Joining是線程同步的方法之一
            當(dāng)且僅當(dāng)線程被設(shè)置為joinable時其可被Joining
            一個例子:
            #include 
            <pthread/pthread.h>
            #include 
            <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <math.h>
            #define NUM_THREADS    4

            void *BusyWork(void *t)
            {
                   
            int i;
                   
            long tid;
                   
            double result=0.0;
                   tid 
            = (long)t;
                   printf(
            "Thread %ld starting\n",tid);
                   
            for (i=0; i<1000000; i++)
                   {
                         result 
            = result + sin(i) * tan(i);
                   }
                   printf(
            "Thread %ld done. Result = %e\n",tid, result);
                   pthread_exit((
            void*) t);
            }

            int main (int argc, char *argv[])
            {
                  pthread_t thread[NUM_THREADS];
                  pthread_attr_t attr;
                  
            int rc;
                  
            long t;
                  
            void *status;

                  
            //! 設(shè)置線程屬性
                  pthread_attr_init(&attr);
                  pthread_attr_setdetachstate(
            &attr, PTHREAD_CREATE_JOINABLE);

                  
            for(t=0; t<NUM_THREADS; t++)
                  {
                        printf(
            "Main: creating thread %ld\n", t);
                        rc 
            = pthread_create(&thread[t], &attr, BusyWork, (void *)t);
                        
            if (rc)
                        {
                                printf(
            "ERROR; return code from pthread_create()is %d\n", rc);
                                exit(
            -1);
                        }
                    }

                    
            //! 銷毀線程屬性
                    pthread_attr_destroy(&attr);
                    
            for(t=0; t<NUM_THREADS; t++)
                    {
                           rc 
            = pthread_join(thread[t], &status);
                           
            if (rc)
                          {
                                  printf(
            "ERROR; return code from pthread_join()is %d\n", rc);
                                  exit(
            -1);
                           }
                           printf(
            "Main: completed join with thread %ld having a status of %ld\n",t,(long)status);
                   }

                   printf(
            "Main: program completed. Exiting.\n");
                   pthread_exit(NULL);
            }

            posted on 2010-12-02 10:15 ccsdu2009 閱讀(363) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


             
            成人久久综合网| 日日躁夜夜躁狠狠久久AV| 久久精品成人免费观看97| 久久综合成人网| 无码超乳爆乳中文字幕久久 | 亚洲va中文字幕无码久久不卡 | 久久亚洲综合色一区二区三区| 国产精品伦理久久久久久| 97精品伊人久久大香线蕉| 日本免费久久久久久久网站| 亚洲精品综合久久| segui久久国产精品| 伊人久久综合精品无码AV专区| 久久精品国产免费一区| 伊人久久综合精品无码AV专区| 精品久久久久久久久久中文字幕 | 久久亚洲电影| 国产精品久久国产精品99盘| 国产精品乱码久久久久久软件 | 91亚洲国产成人久久精品网址| 久久久久久国产精品美女| 精品久久久久久无码中文野结衣 | 99久久99久久精品国产片果冻| 色综合久久久久综合体桃花网| 亚洲精品第一综合99久久 | 99久久婷婷免费国产综合精品| 国产成人精品久久| 国产精品久久久久久久人人看 | 国产情侣久久久久aⅴ免费| 三上悠亚久久精品| 久久精品国产亚洲av麻豆色欲| 国内精品久久久久久久久电影网 | 日本久久久久久中文字幕| 久久精品国产91久久麻豆自制 | 亚洲精品高清国产一久久| 国产91色综合久久免费| 97久久精品无码一区二区| 久久久久高潮毛片免费全部播放| 久久国产精品77777| 色综合久久最新中文字幕| 国产精品热久久毛片|