Binding multiple pthreads, each to the same member function of a different object from the same class -


i have bound multiple pthreads independent member function of independent objects same class.

i had use of static member function helper since not possible bind member function directly pthread in c++; however, application behaves strangely , suspicious use of static function, since static function shared between objects of same class.

is type of usage right? there alternative solution?

i appreciate hear guidance.

class region { public:      region();      void init();      void push_tuple(int int_value, float float_value, bool tuple_source);      static void *read_tuple_r_process_s_update_helper(void *context)     {         return ((region *)context)->read_tuple_r_process_s_update();     }     void* read_tuple_r_process_s_update();      static void *read_tuple_s_process_r_update_helper(void *context)     {         return ((region *)context)->read_tuple_s_process_r_update();     }        void* read_tuple_s_process_r_update(); };  int main(){      region regions[thread_count*2];       for(int i=0; < thread_count*2; i++){         regions[i].init();     }      pthread_t thread_id[thread_count*2];     void* exit_status;      for(int i=0; < thread_count; i++){         pthread_create(&thread_id[i], null, &region::read_tuple_r_process_s_update_helper, &regions[i]);     }      for(int i=thread_count; < thread_count*2; i++){         pthread_create(&thread_id[i], null, &region::read_tuple_s_process_r_update_helper, &regions[i]);     }         for(int i=0; < thread_count*2; i++){         pthread_join(thread_id[i], &exit_status);     }  return 0; } 

although suspected binding described, not source of problem , works correctly. problem waiting while loops affected optimizer! using volatile keyword solved problem.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -