Posted on 2000-04-21
This is probably an easy question for all the thread masters out there, but I'm not sure of the best way to implement this being a thread newbie.
1) Basically, I have a master thread that receives TCPIP messages from a socket.
2) Then I also have several client threads that are blocked waiting for an event(WaitForSingleObject).
3) When the master thread receives a complete message, it stores the message in a global buffer and fires an event. (PulseEvent).
4) This releases each of the client threads and they read the global buffer and store/process it locally.
The problem is that sometimes I get a burst of TCPIP messages faster than the client threads can process each message. This results in messages getting dropped.
So what I would like to do is block the master thread until all of the client threads have completed each message.
Does anybody have any suggestions as to what the best implementation is to accomplish this while avoiding race conditions, deadlock, etc? Is it possible to use a semaphore that only signals when a certain number is reached?