c - Thread Pool using pthreads -
so, questions how should create thread pool of pthreads? need create amount of pthreads based on global variable:
#define num_processes 10
so, idea create array stores pthreads may use them needed. have mutex lock pseudo-code setup controlling ones running. i'm having trouble how implement thread creation based on #define statement.
so c / idea is;
pthread_t *mypthreadids[num_processes]; pthread_attr_t threadattributes; pthread_attr_init(&threadattributes); for(i = 0; < num_processes; i++){ pthread_create(&mypthreadids[i], &threadattributes, thread_run, thetime); }
my question is, can create pthread pointers way?
edit:
so answer or fixing mistake on line:
pthread_t *mypthreadids[num_processes];
i needed change to:
pthread_t mypthreadids[num_processes];
it's important note confusion pthread_t type , declaring have pool. pthread_t not address , did not need create array of type pointers.
thanks @whozcraig!
Comments
Post a Comment