Click here to Skip to main content
15,742,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hey everybody. I have a quick question on multithreading for an application that listens for feeds over a network.

The question is if you have an app that is supposed to listen for data over multiple multicast channels (multiple being you don't really now how many they can be 10 channels they could be 20) whats the most efficient way to build this application in terms of thread creation.. Should each channel you are listening on create its own thread or should you listen using only a single thread?

The question is based purely on an efficiency standpoint for the design of the app.

Please share your thoughts
Richard MacCutchan 10-Apr-15 11:15am    
That is impossible to answer, since so much depends on other factors. The only way to resolve the question is by trying some different configurations and measuring performance.
Sergey Alexandrovich Kryukov 10-Apr-15 15:26pm    
Yes, that makes sense.

1 solution

No. It would not make sense in the case of unpredictable number of channels, and simply unsafe. You do need threads, but too many threads would only compromise throughput, because threading itself has its overhead. Performance of the system can grow with adding threads only with the number of the threads not exceeding the total number of CPU cores. Generally, performance was not a goal of threading.


Face it, threading itself has its considerable overhead. If you have 4 CPU cores and some job not logically requiring threading, you can split it into 4 and improve total completion time, but only if the work is big enough. If you split it between 20 thread, it may take more time to complete.

Share this answer
Member 11596964 10-Apr-15 11:29am    
Ok thanks, but it is possible that you have 20 channels to listen to for example but less than 20 cores. All 20 can have data simultaneously, and you want to perform tasks with the data. So how do you suggest going about this? And yes there is overhead with threads but the question is about the most efficient way to cut down overhead.
Sergey Alexandrovich Kryukov 10-Apr-15 11:44am    
Possible, but hardly makes a lot of sense. I did not think of the architecture using UDP, but I have some answers (based on really good experience) related to threading and number of threads using TCP channels. They would not be applicable to your situation, but what if it can give you some ideas?
So, under this disclaimer, here:,,

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