c語言多線程編程使用示例
#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;
}
相關(guān)文章
關(guān)于Visual Studio無法打開源文件"stdio.h"問題
這篇文章主要介紹了關(guān)于Visual Studio無法打開源文件"stdio.h"問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04

