hello-solution.c
来自「Pthreads是Intel开发的Linux下的多线程编译工具」· C语言 代码 · 共 30 行
C
30 行
#include <stdio.h>#include <pthread.h>#define NUMTHREADS 4void *helloFunc(void *pArg) { int myNum = *((int *)pArg); printf("Hello from Thread #%d\n", myNum); }main() { pthread_t hThread[NUMTHREADS]; int tNum[NUMTHREADS]; for (int i = 0; i < NUMTHREADS; i++) { tNum[i] = i; pthread_create(&hThread[i], NULL, helloFunc, &tNum[i]); } for (int j = 0; j < NUMTHREADS; j++) pthread_join(hThread[j], NULL); return 0; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?