通过本文主要向大家介绍了c语言代码示例,c语言简单代码示例,c语言流程图示例,c语言示例程序,c程序示例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
#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;
}
</div>