现在的位置: 首页 > 综合 > 正文

线程——create pthread

2017年12月15日 ⁄ 综合 ⁄ 共 549字 ⁄ 字号 评论关闭

//
// create a pthread
//   int pthread_create(pthread_t *restrict thread,
//                 const pthread_attr_t *restrict attr,
//              void *(*start_routine)(void*), void *restrict arg);
//

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

static void *func(void *p)
{
 puts("Thread is working!");
// return NULL;
 pthread_exit(NULL);
}

int main()
{
 int err;
 pthread_t tid; //线程标识

 puts("Begin!");
 //
 err = pthread_create(&tid,NULL,func,NULL);
 if(err)
 {
  fprintf(stderr,"pthread_create():%s\n",strerror(err));
  exit(1);
 }
 pthread_join(tid,NULL);//收尸

 
 puts("End!");

 exit(0);
}

 

抱歉!评论已关闭.