文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>线程属性(线程分离)

线程属性(线程分离)

时间:2010-12-11  来源:luozhiyong131

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void mythread()
{
    printf("thread is pthread:n");
    sleep(1);
    printf("thread is exitingn");
    int thread_finished = 1;
    pthread_exit(NULL);
}

int main()
{
    pthread_t id;
    pthread_attr_t thread_attr;
    int ret,thread_finished;
    ret = pthread_attr_init(&thread_attr);
    if(ret!=0)
    {
        printf("pthread_attr_init errorn");
        exit(1);
    }
    
    ret = pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);
    if(ret!=0)
    {
        printf("pthread_attr_setdetachstate errorn");
        exit(1);
    }
    
    ret = pthread_create(&id,&thread_attr,(void *)mythread,NULL);
    if(ret!=0)
    {
        printf("create pthread errorn");
        exit(1);
    }    
    
    while(!thread_finished)
    {
        printf("waitint for thread finished..n");
        sleep(1);
    }
    printf("Donen");
    return 0;    
}



相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载