pointers - C thread argument -
basic function of program: create number of counters (0), create number of instructions per threads, create struct instructions contain counter*, repetitions , work_fn (increment, decrement etc). program build dynamic structure (already coded up) spawn threads , join. 1 thread can have more 1 instructions.
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 total number of threads for(int i=0; < nthreads ; i++){ pthread_create( &thread_id[i], null, worker_thread, &i); //problem } for(int i=0; < nthreads ; i++){ pthread_join( thread_id[i], null); }
i trying test thread function, firstly create number of threads join them. can't seems pass current thread number [i] in case worker thread function.
int n = (int)arg;
in worker_thread function.
and
(void*)i
instead of &i
in thread spawn
Comments
Post a Comment