共享内存,共享缓冲区 一对多

时间:2022-03-21 12:19:20

produce:

for(int i=0;i<m_push_thread;i++){

if(iter == VecS2SResult.end()){
break;
}
if(g_Empty_sem_obj[i].sem_trywait()==0){
//获取到信号量

g_push_consume_cache[i].msgid = (*iter)["FmsgId"];
g_push_consume_cache[i].appid = (*iter)["Fappid"];

iter = VecS2SResult.erase(iter);
g_Full_sem_obj[i].sem_post();
}

}

consume:

while(1){
//等待信号量
g_Full_sem_obj[threadId].sem_wait();
do_something();
g_Empty_sem_obj[threadId].sem_post();
}