国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C > 正文

c語言線程終止練習示例

2020-01-26 15:32:31
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

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

void *t1(void *args) {
 return (void *) 0;
}

void *t2(void *args) {
 printf("thread 2 param[args] = %d/n", args);
 pthread_exit((void *) 3);
}

void *t3(void *args) {
 while(1) {
  printf("thread 3 is working/n");
  sleep(1);
 }
}

int main(int argc, char *argv[]) {
 pthread_t thread;
 int err;
 void *status;

 printf("creating thread 1/n");
 err = pthread_create(&thread, NULL, t1, NULL);
 if(err) {
  printf("Can not created thread 1/n");
  exit(-1);
 }
 pthread_join(thread, &status);
 printf("thread 1 exit return code %d/n/n", status);
 

 printf("creating thread 2/n");
 err = pthread_create(&thread, NULL, t2, (void *) 9);
 if(err) {
  printf("Can not created thread 2/n");
  exit(-2);
 }
 pthread_join(thread, &status);
 printf("thread 2 exit return code %d/n/n", status);

  
 printf("creating thread 3/n");
 err = pthread_create(&thread, NULL, t3, NULL);
 if(err) {
  printf("Can not created thread 3/n");
  exit(-3);
 }
 sleep(10);
 pthread_cancel(thread);
 pthread_join(thread, &status);
 printf("thread 3 exit return code %d/n", status);

 return 1;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 楚雄市| 广水市| 连山| 浏阳市| 西林县| 靖宇县| 当阳市| 汕头市| 浠水县| 鄂州市| 闽侯县| 托克托县| 汤阴县| 中西区| 德庆县| 土默特左旗| 怀远县| 贡觉县| 洞口县| 连南| 宁武县| 广东省| 贵阳市| 额济纳旗| 嘉祥县| 大邑县| 都兰县| 英吉沙县| 金秀| 遂宁市| 内乡县| 双城市| 北川| 河间市| 新津县| 高州市| 广宁县| 文山县| 华宁县| 白银市| 吕梁市|