c++ Producer Consumer Code Design -


i have design producer consumer problem restrictions.

struct data{     int id;     int value; };  std::list<struct data> g_dataq;  class consumer{     void process_data(){         struct data my_data = g_dataq.pop_front();         if(my_data.id == 0){           //consumer 0         }else if(my_data.id == 1){           //consumer 1         }         //process data     } };  void consume(struct data pdata){     g_dataq.push_back(pdata); } 

description:

producer calling "consume" function. , there can multiple producer/consumer. data consumed current consumer determined data.id. every consumer instantiate class consumer. there 1 consume function.

restrictions have:

  1. "consume" function has global.
  2. there can multiple producer/consumer

my main concern having global g_dataq. 1 way resolve having list of list first dimension handles consumer belongs to.

my query can done without making q global?

thanks in advance.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -