首页 > 编程语言 > 详细

线程退出前操作

时间:2014-06-15 13:13:20      阅读:399      评论:0      收藏:0      [点我收藏+]
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

void cleanup()
{
    printf("cleanup\n");
}

void *test_cancel(void)
{
    pthread_cleanup_push(cleanup,NULL);
    printf("test_cancel\n");

    while(1)
    {
        printf("test message\n");
        sleep(1);
    }
    pthread_cleanup_pop(0);
}
int main()
{
    pthread_t tid;
    pthread_create(&tid,NULL,(void *(*)(void *))test_cancel,NULL);
    sleep(2);
    pthread_cancel(tid);
    pthread_join(tid,NULL);
    return 0;
}

bubuko.com,布布扣

线程退出前操作,布布扣,bubuko.com

线程退出前操作

原文:http://www.cnblogs.com/lakeone/p/3789274.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!