My topic may be somewhat off topic to opengl, if so, I apologize in advance.

I am programming a multiplayer game, what I did is implementing the synchronization logic in the server module. And the problem I encountered is that I can not find a efficient way to block each client until all the clients have sent their frame data to the server. My thread code looks like this:

// After the server received a client’s data. ClientID is the ID that the thread deals with.

But you can see that there is an obvious fault in this code, since there is the possibility that one client can go through the thread code without waiting for other clients. Can anybody give me some answer or ideas? Thanks so much