Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Supose i have a network server and some clients writes data to other clients, just like a chat. If i use and IOCP (IO Completion Port) design and i have 4 threads waiting for messages. When those threads received data i need to serialize the access to the client list to get the socket descriptor of the client/s i need to resend the received data.

By doing this i think i am loosing all the scalability that IOCP offers. Becase my 4 threads now use Mutexes or Critical Sections around the client list.

To be more especific: clients has names, so one client writes to one or more clients by name. Then i have to find the socket descriptors related to those names when each message arrive to the server.

So my questions are:
1- Is IOCP still superior/scalable than Asynchronous sockets (WSAAsyncSelect) with one dedicated thread to the window that process the messages (for this case)?
2- There is a better design to avoid the use of Mutexes/CSs?
Posted

1. Depends on how you use it. The devil is in the details.

2. Yes. The client list should be accessed by only one thread. This thread can tell the other 4 threads to resend using IOCP or standard windows message.
 
Share this answer
 
1 - You could use a single writer multiple reader lock around your client list.

2 - You could reference count the client objects, you then only need to hold the lock on the client list for long enough to obtain the client object rather than for the whole send operation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900