国产探花免费观看_亚洲丰满少妇自慰呻吟_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;
}

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

圖片精選

主站蜘蛛池模板: 台东市| 天水市| 石狮市| 龙游县| 信阳市| 井冈山市| 宽城| 永宁县| 西乌珠穆沁旗| 新民市| 鸡西市| 汤阴县| 枝江市| 南丰县| 嵊州市| 黑龙江省| 东阳市| 新沂市| 衢州市| 曲水县| 东阳市| 凌云县| 惠来县| 湛江市| 绥滨县| 师宗县| 五大连池市| 灵寿县| 霍山县| 菏泽市| 嘉兴市| 江永县| 马山县| 农安县| 临西县| 中山市| 富宁县| 苍南县| 临湘市| 黄梅县| 百色市|