【发布时间】:2020-03-22 07:17:42
【问题描述】:
我想从连接到我的服务器的所有客户端收集数据,我想最多等待 1 秒。如何用信号量做到这一点? 我当前的代码:
int players=2;
while(1){
//request for choice
for(int i = 0; i<players; i++)
sem_post(&sharedMemory->request_choice);
//wait for data
for (int i = 0;i<players; i++)
//ok..I have data but not in 1 second..
sem_wait(&sharedMemory->got_choice);
//updating data..
}
【问题讨论】: