++

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

linux 线程相关

编译加上参数

gcc -lpthread

--------------1.1第一个线程---

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

int * thread(void *arg)
{
        printf("thread id is %d.\n",pthread_self());
        return NULL;
}

int main()
{
    pthread_t id;
    printf("Main thread id is %d \n",pthread_self());
    if(!pthread_create(&id,NULL,(void *)thread,NULL))
    {
       printf("succeed!\n");
       return 0;
    }
    else
    {
       printf("Fail to Create Thread");
       return -1;
    }

-----------1.1 end ------

 

 

 

posted on 2012-01-19 05:56  自制力缺失症患者  阅读(88)  评论(0)    收藏  举报