What is TPL ( Task Parallel Library) and how it differs from threads (c# interview questions) ?

preview_player
Показать описание

See our other Step by Step video series below :-

In this video we will see 3 big uses of TPL( Task parallel library)
parallel processing,pooling and abstraction. We also point how threads differ from threads.

We are also distributing a 200 page Ebook ".NET Interview Question and Answers". If you want this ebook please share this video in your facebook/twitter/linkedin account and email us on
Рекомендации по теме
Комментарии
Автор

Do not miss our Interview Question video series

dnfvideo
Автор

After inserting the Parallel.For-Call the total amount of iterations is 1, 000, 000 * 1, 000, 000. For unexperienced viewers leaving the old for loop in the program could be confusing.

CedricReinsch
Автор

Questpond helped me crack so many software interviews. Thank you Shiv Prasad sir.

rahulmathew
Автор

Questpond has top notch videos and the explanations are among the best anywhere. Especially the design patterns series - simple to grasp some complex subjects! Excellent job Questpond! I'll likely sign up with them shortly.

rondanish
Автор

You are so right. But well the TPL example was super loaded
with 1 million time more but still performed better. So it sill conveys the same message TPL is better.

So sorry i was so engrossed in the avoid night recordings.

dnfvideo
Автор

There seems to be a misconception here, when we spawn a new thread like shown in first part off video, it is not for completing task faster, it is just for making calling thread free and assigning task to another thread. By this its obvious that all cores of cpu will not take same load. Because spawned thread running on one core is processing assigned task and meanwhile calling thread finishes with main function.

ashishtrivedi
Автор

examples show are different but proves the point anyways that TPL has better performance than threads.

PlayA
Автор

Nice video. thanks to the creator. However, it raises a few questions:

1. What if I wish to run a task forever according to its own logic
(in which case the 'For" of the Parallel.For is not required).
Thus, I need a one time launch ... and let the thread run as long as its own logic says so.

2. How do I enquire a core's overload to correctly set task-core affinity?

3. Which API is used to set affinity?

4. I don't understand why the Parallel.For is used ... there is a for () loop statement in the task's code?


5. It is unclear to me from the core overload chart whether we see 4 identical tasks running on 4 cores concurrently?

If this is a single task running on all 4 cores. then:
(a) what exactly controls splitting its work among cores and then combine the results as if it was executed on a single core.
(b) how come the overload of all cores is similar to the overload of the execution of a single core. Where is the benefit?
in the execution period length?

ShukyPersky
Автор

I think we do not need "for loop" in the method while we are using parallel class in the example mentioned in the video..   

himanshujain
Автор

Good video showing concept of TPL but in this example diagram showing running multiple cores of 1/2 millions iterations each but code shows running multi cores of millions iterations which I don't quite follows. How do you knows that tasks of computing spread equally.

PakredBoz
Автор

"P2" is typically used to refer to the "Pentium 2" processor. A processor with 2 cores is referred to as a "dual core" processor and a system with 2 processors is referred to as a "dual processor" system (a dual processor system can have more than 2 cores).

knitinr
Автор

Very nice video. Where is the next part of TPL tutorial

rajinira
Автор

To increase utilization, you should create multiple threads. As you have 4 cores, creating 4 threads with each running the RunMillionIterations would show you a high CPU utilization.

knitinr
Автор

Quick question? I see with Task.Parallel you are manully creating 1, 000, 000 task which are running in parallelly across multiple core using Task.Parallel, same thing can be acheived using multi-threading if you create 1, 000, 000 task and cpu will schedule them to run across different core's. Your earlier example where you are running a for loop will also run on single core even when we use Task.Parallel.

TPL or Parallel.For does not distribute a single task across multiple cores. A single task runs on one core. To utilize multiple cores, you need to break the workload into multiple parallel tasks.

Can you correct me here if I am missing something?

rohit.badgujar
Автор

I love your concise to the point tutorials....Very helpful.

Tall-Cool-Drink
Автор

Nice video with ample of information demonstrating comparison of legacy multi threading and modern TPL

vkg.codefactory
Автор

Summary -
Task is an encapsulation on Theads

Task Parallel Library: Helps in maximal utilization of all cores present in system which increases performance of an application

trijay
Автор

Correct me if am wrong, Parallel.For runs  from 0 to million each time it calls a function RunMillionIterations(). This means that the each function call will be divided among processors/ available threads. However, i see the explanation saying the whole iteration is divided among iteration that is kind of confusing. 

mvkotekar
Автор

In your video related to Concurrency vs Parallelism you have said when two thread is running in parallel then there is no context switching and because of it performance of the application improve. But in this video you are saying there is a time slicing or context switching when two thread runs a task but how it happens I am not understanding it.

mojeebhasan
Автор

I have to say that concatenating a string with s = s+"x" one million times is absolute a killer for memory and GC

felixpollan