Linux创建线程

#include"stdio.h"  
#include"pthread.h"  
#include"unistd.h"  
static shdata=4;  
void *create(void *arg)  
{  
    printf("New pthread......\n");  
    printf("shared data=%d \n",shdata);  
    return(void *)0;  
}  
int main()  
{  
    pthread_t tid;  
    int error;  
    error=pthread_create(&tid,NULL,create,NULL);  
    if(error!=0)  
    {  
        printf("thread is not created...\n");  
        return -1;  
    }  
    printf("main pid is %d\n",getpid());  
    sleep(1);  
    printf("线程创建成功!\n");  
    return 0;  
}  
 
 

//本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/702536

 

posted @ 2014-08-10 10:03  商商-77  阅读(185)  评论(1编辑  收藏  举报