Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threads or asynch?

How do you make your application multithreaded ? Do you use asynch functions ? or do you spawn a new thread ? I think that asynch functions are already spawning a thread so if your job is doing just some file reading, being lazy and just spawning your job on a thread would just "waste" ressources... So is there some kind of design when using thread or asynch functions ?

like image 963
CiNN Avatar asked Sep 14 '08 13:09

CiNN


1 Answers

If you are talking about .Net, then don't forget the ThreadPool. The thread pool is also what asynch functions often use. Spawning to much threads can actually hurt your performance. A thread pool is designed to spawn just enough threads to do the work the fastest. So do use a thread pool instead of spwaning your own threads, unless the thread pool doesn't meet your needs.

PS: And keep an eye out on the Parallel Extensions from Microsoft

like image 182
Lars Truijens Avatar answered Oct 23 '22 03:10

Lars Truijens