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:
- "consume" function has global.
- 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
Post a Comment