雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

c語言多線程編程使用示例

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊:

復(fù)制代碼 代碼如下:

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

#define THREAD_NUM 10

void *test(void *args) {
 printf("tid %d: i say 'Hello'.\n", args);
 return NULL;
}

int main() {
 int i, err;
 pthread_t child[THREAD_NUM];

 for(i = 0; i < THREAD_NUM; i++) {
  printf("Creating thread %d\n", i);
  err = pthread_create(&child[i], NULL, test, (void *) i);
  if(err) {
   printf("Can't create thread %d\n", i);
   exit(0);
  }
 }

 for(i = 0; i < THREAD_NUM; i++)
 pthread_join(child[i], NULL);

 printf("Thread initialize\n");
 return 0;
}

上一篇:window調(diào)用api列出當(dāng)前所有進(jìn)程示例

欄    目:C語言

下一篇:使用dc畫筆畫矩形、直線與橢圓示例

本文標(biāo)題:c語言多線程編程使用示例

本文地址:http://www.jygsgssxh.com/a1/Cyuyan/3695.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有