【发布时间】:2011-08-15 11:43:02
【问题描述】:
我的程序的基本功能:创建计数器数量(0),创建每个线程的指令数量,创建包含计数器*、重复和 work_fn(递增、递减等)的结构指令。 程序将构建所有的动态结构(已经编码) 然后产生线程并加入。一个线程可以有多个指令。
static void* worker_thread(void *arg){
long long *n;
pthread_mutex_lock( &lock1 );
n = (long long *) arg;
printf("Testing: %lld.\n", n);
pthread_mutex_unlock( &lock1 );
return NULL;
}
//nthreads is the total number of threads
for(int i=0; i < nthreads ; i++){
pthread_create( &thread_id[i], NULL, worker_thread, &i); //Problem
}
for(int i=0; i < nthreads ; i++){
pthread_join( thread_id[i], NULL);
}
我正在尝试测试线程功能,首先创建线程数然后加入它们。 但在我的情况下,我似乎无法将当前线程号 [i] 传递给工作线程函数。
【问题讨论】: