Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task Parallel library vs Native Thread Synchronization

Tags:

c#

This question may be subjective but i just want to know when to use TPL and when to use native thread based synchronization (evnts, wait handles).

Will the native thread synchronization techniques be obsolete going forward?

Thanks

like image 821
TalentTuner Avatar asked Oct 21 '10 07:10

TalentTuner


1 Answers

Use TPL wherever you can because it's a cleaner, more declarative way to express your needs for parallelism.

MSDN explains "The TPL scales the degree of concurrency dynamically to most efficiently use all the processors that are available. In addition, the TPL handles the partitioning of the work, the scheduling of threads on the ThreadPool, cancellation support, state management, and other low-level details. By using TPL, you can maximize the performance of your code while focusing on the work that your program is designed to accomplish."

See also http://www.albahari.com/threading/part5.aspx which details the benefits of 'Data Parallelism' and other TPL benefits.

like image 125
Ian Mercer Avatar answered Sep 25 '22 05:09

Ian Mercer