c语言线程代码如下:#include#include#includevoid*t1void*argsreturnvoid*0;void*t2void*argspri下面是小编为大家整理的c语言线程终止练习示例,供大家参考。
c语言线程
代码如下:
#include
#include
#include
void *t1void *args
return void * 0;
void *t2void *args
printf"thread 2 param[args] = %dn", args;
pthread_exitvoid * 3;
void *t3void *args
while1
printf"thread 3 is workingn";
sleep1;
int mainint argc, char *argv[]
pthread_t thread;
int err;
void *status;
printf"creating thread 1n";
err = pthread_create&thread, NULL, t1, NULL;
iferr
printf"Can not created thread 1n";
exit-1;
pthread_jointhread, &status;
printf"thread 1 exit return code %dnn", status;
printf"creating thread 2n";
err = pthread_create&thread, NULL, t2, void * 9;
iferr
printf"Can not created thread 2n";
exit-2;
pthread_jointhread, &status;
printf"thread 2 exit return code %dnn", status;
printf"creating thread 3n";
err = pthread_create&thread, NULL, t3, NULL;
iferr
printf"Can not created thread 3n";
exit-3;
sleep10;
pthread_cancelthread;
pthread_jointhread, &status;
printf"thread 3 exit return code %dn", status;
return 1;
推荐访问:示例 线程 终止 c语言线程终止练习示例 c语言线程终止练习示例 c语言停止线程 c++终止线程