多线程执行一段程序
void* say_hello(void* args)
{
int tid = *((int*)args);
printf("i = %d\n", tid);
}
pthread_t tids[NUM_THREADS];
int indexes[NUM_THREADS];
for(int i = 0; i < process_no; ++i)
{
indexes[i] = i;
int ret = pthread_create(&tids[i], NULL, say_hello, (void *)&(indexes[i]));
if (ret != 0)
{
std::cout << "pthread_create error: error_code=" << ret << std::endl;
}
}
void *status;
for( int i = 0; i < process_no; ++i )
{
int ret = pthread_join( tids[i], &status );
if( ret != 0 )
{
std::cout << "pthread_join error:error_code=" << ret << std::endl;
}
}