I have problem with simple short code. It's example of usage of TCP communication. 6 Client processes initialized with fork() are sending simultaneously random numbers from 1 to 5 to server (in a infinite loop with random pause before sending another number) . Server responds with the same number. To receive and respond server uses threads in a loop.

Loop waits for connection and when some process wants to connect it creates one thread for it. So we have 6 client processes and 6 server threads.

The problem- All threads are used in the communication but not all server processes are used. When I use only 3 threads and processes instead of 6 all are in use. When I use 6 processes only 4 are in use. When I use 30 only ONE process is receiving and responding.

Maybe someone know how to make ALL processes to work in communication?