[Linux线程]使用pthread_create函数来创建一个线程
#include<stdio.h>#include<stdlib.h>#include<pthread.h>//新线程首先运行的函数void*threaddeal(void*arg){printf("这是一个新线程.\n");//输出新线程提示}intmain(intarg,char*argv[]){pthread_tthreadid;//线程的标识符if(pthread_create(&threadid,NULL,threaddeal,NULL)!=0)//创建一个新县城,然后运行threaddeal函数{//如果返回值不是0则表示创建线程失败printf("%s错误出现在第%s行",__FUNCTION__,__LINE__);//打印错误信息exit(0);}else{sleep(1);//挂起1秒等待线程运行}return0;}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。