100-C++
来源:互联网 发布:java开发框架课程设计 编辑:程序博客网 时间:2024/05/29 14:14
向线程传参数
#include <iostream>#include <cstdlib>#include <pthread.h> using namespace std; #define NUM_THREADS 5 struct thread_data{ int thread_id; char *message;}; void *PrintHello(void *threadarg){ struct thread_data *my_data; my_data = (struct thread_data *) threadarg; cout << "Thread ID : " << my_data->thread_id ; cout << " Message : " << my_data->message << endl; pthread_exit(NULL);} int main (){ pthread_t threads[NUM_THREADS]; struct thread_data td[NUM_THREADS]; int rc; int i; for( i=0; i < NUM_THREADS; i++ ){ cout <<"main() : creating thread, " << i << endl; td[i].thread_id = i; td[i].message = "This is message"; rc = pthread_create(&threads[i], NULL, PrintHello, (void *)&td[i]); if (rc){ cout << "Error:unable to create thread," << rc << endl; exit(-1); } } pthread_exit(NULL);}
阅读全文
0 0
- [C] C程序100例_001
- [C] C程序100例_002
- [C] C程序100例_003
- [C] C程序100例_004
- [C] C程序100例_005
- [C] C程序100例_006
- [C] C程序100例_007
- [C] C程序100例_008
- [C] C程序100例_009
- [C] C程序100例_010
- [C] C程序100例_011
- [C] C程序100例_012
- [C] C程序100例_013
- [C] C程序100例_014
- [C] C程序100例_015
- [C] C程序100例_016
- [C] C程序100例_017
- [C] C程序100例_018
- 096-C++
- poj 3126 Prime Path(广搜)
- 097-C++
- 098-C++
- 099-C++
- 100-C++
- HDU 1495 非常可乐(广搜)
- vim键位映射map
- Linux和Windows下安装最新版Git+教程
- cocos creator 中使用自定义shader
- LLVM\Clang 在Windows下可运行的配置
- 3D渲染管线基本的流程及其流程图
- next_permutation函数 (1)
- next permutation函数(2)