电子文章 | 电子资料下载 | 家电维修 | 维修资料下载 | 加入收藏 | 全站地图
您现在所在位置:电子爱好者电子文章EDA/PLD线程解析(二)

线程解析(二)

11-20 00:29:46 | http://www.5idzw.com | EDA/PLD | 人气:282
标签:eda技术,eda技术实用教程,http://www.5idzw.com 线程解析(二),http://www.5idzw.com
                        perror("setcancelstate");
                }
                if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL) != 0)
                {
                        perror("setcancelsype");
                }
                while(1)
                {
                        sleep(1);
                        printf("thread_a\n");
                        pthread_testcancel();
                }
        }

void *thread_b(void *arg)
        {

        if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL) != 0)
                {
                        perror("setcancelstate");
                }
                while(1)
                {
                        sleep(1);
                        printf("thread_b\n");
                        pthread_testcancel();
                }
        }

void *thread_c(void *arg)
        {
                if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL) != 0)
                {
                        perror("setcancelstate");
        }

        if(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL) != 0)
                {
                        perror("setcancelsype");
                }

        while(1)
                {
                        sleep(1);
                        printf("thread_c\n");
                        pthread_testcancel();
                }
        }

int main(int argc, char **argv)
        {
                pthread_t tid_a,tid_b,tid_c;
                int err;

        err = pthread_create(&tid_a,NULL,thread_a,(void *)&tid_a);
                if(err < 0)
                {
                        perror("pthread_create thread_a");
                }
                printf("create tid_a = %u\n",tid_a);
                err = pthread_create(&tid_b,NULL,thread_b,(void *)&tid_b);
                if(err < 0)
                {
                        perror("pthread_create thread_b");
                }

上一页  [1] [2] [3]  下一页

,线程解析(二)
关于《线程解析(二)》的更多文章