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

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ธ.ค. 2024

ความคิดเห็น • 85

  • @dnfvideo
    @dnfvideo  3 ปีที่แล้ว

    Do not miss our Interview Question video series
    30 Important C# Interview Questions : th-cam.com/video/BKynEBPqiIM/w-d-xo.html
    25 Important ASP.NET Interview Questions : th-cam.com/video/pXmMdmJUC0g/w-d-xo.html
    25 Angular Interview Questions : th-cam.com/video/-jeoyDJDsSM/w-d-xo.html
    5 MSBI Interview Questions : th-cam.com/video/5E815aXAwYQ/w-d-xo.html

  • @CedricReinsch
    @CedricReinsch 10 ปีที่แล้ว +67

    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.

    • @vb7813
      @vb7813 9 ปีที่แล้ว +2

      +Cedric Reinsch
      Yeah! I was thinking the very same thing!
      However I don't think it would have affected the processor core loading. But it would have affected the core usage and also the total exec time.

  • @rahulmathew8713
    @rahulmathew8713 2 ปีที่แล้ว +1

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

  • @rondanish5041
    @rondanish5041 8 ปีที่แล้ว +2

    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.

  • @dnfvideo
    @dnfvideo  11 ปีที่แล้ว +6

    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 demo......Should avoid night recordings.

  • @Tall-Cool-Drink
    @Tall-Cool-Drink 7 ปีที่แล้ว

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

  • @himanshujain12221
    @himanshujain12221 10 ปีที่แล้ว +22

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

  • @knitinr
    @knitinr 11 ปีที่แล้ว +1

    "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).

  • @PlayA011
    @PlayA011 11 ปีที่แล้ว +5

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

  • @vkg.codefactory
    @vkg.codefactory 9 ปีที่แล้ว +1

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

  • @PakredBoz
    @PakredBoz 10 ปีที่แล้ว +7

    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.

  • @ashishtrivedi8739
    @ashishtrivedi8739 7 ปีที่แล้ว +3

    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.

  • @knitinr
    @knitinr 11 ปีที่แล้ว +1

    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.

  • @Aquineas
    @Aquineas 6 ปีที่แล้ว

    Fast-forward to 8:31 if you already understand threading and using perfmon and actually wish to get to TPL.

  • @ShukyPersky
    @ShukyPersky 5 ปีที่แล้ว +1

    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?

  • @mojeebhasan5283
    @mojeebhasan5283 3 ปีที่แล้ว +1

    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.

  • @rajinira
    @rajinira 5 หลายเดือนก่อน

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

  • @rohit.badgujar
    @rohit.badgujar 3 หลายเดือนก่อน

    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?

  • @MrKsackel12345
    @MrKsackel12345 8 ปีที่แล้ว

    really good video. what i suspected was happening but very clever way of proving it.

  • @felixpollan
    @felixpollan 5 ปีที่แล้ว +2

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

    • @dinesh241290
      @dinesh241290 4 ปีที่แล้ว

      we can use 'StingBuilder' instead of 'String'

  • @mvkotekar
    @mvkotekar 10 ปีที่แล้ว +2

    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.

  • @nathanfmaddock
    @nathanfmaddock 11 ปีที่แล้ว +2

    Hi, Great video, where are the other parts to it?

  • @asingb
    @asingb 10 ปีที่แล้ว +1

    You are awesome sir.. really you always explain complex things in simple way. that a layman can understand.. thank you for sharing ..

  • @rochlani_gul
    @rochlani_gul 10 ปีที่แล้ว +6

    Author seems to be under impression that PII processor means processor have two cores. Rather PI to PIV are all single core processors, only after arrival of dual core pentiums we had multiple cores and later it was followed by core 2, I3,I5,I7.

  • @DDD-bt8gj
    @DDD-bt8gj 3 ปีที่แล้ว

    Great explanation!

  • @fordfiveohh
    @fordfiveohh 9 ปีที่แล้ว

    How do thread branches execute? If I spawn a thread from a thread does it time slice or does it parallelize. I guess I could experiment and find out.

  • @vbansal1984
    @vbansal1984 10 ปีที่แล้ว

    awesome. love the explanation of all your videos.

  • @luckyguest6027
    @luckyguest6027 8 ปีที่แล้ว

    Good video. Liked the perfmon demo.

  • @mojeebhasan5283
    @mojeebhasan5283 3 ปีที่แล้ว

    Can we Eecute a long running in single core using two thread?

  • @Prakash12312
    @Prakash12312 9 ปีที่แล้ว

    nice explanation. Awesome work.

  • @trijay
    @trijay 6 หลายเดือนก่อน

    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

  • @expertreviews1112
    @expertreviews1112 3 ปีที่แล้ว

    Love the video but where's the 2nd part? cant find it...

  • @mojeebhasan5283
    @mojeebhasan5283 3 ปีที่แล้ว

    If we execute multi thread in a single core then it context switching will happen? Am I right?

  • @magnusfountains
    @magnusfountains ปีที่แล้ว

    please provide link for 2nd part.

  • @floflodu
    @floflodu 9 ปีที่แล้ว

    This video really helped me. Thank you !

  • @bharatVarshMahan
    @bharatVarshMahan 3 ปีที่แล้ว

    very good video

  • @MichaelBeck_profile
    @MichaelBeck_profile 9 ปีที่แล้ว

    What a nice tutorial!

  • @chayankar2905
    @chayankar2905 10 ปีที่แล้ว

    good tutorial .. liked it !!

  • @suriyae.s2107
    @suriyae.s2107 ปีที่แล้ว

    Great! Thanks

  • @wahidmasud5772
    @wahidmasud5772 4 ปีที่แล้ว +1

    Try executing 10 million iterations and you'll see the performance is actually decreasing. In my Ryzen 3400g CPU, 10M sequential loop takes 200 seconds and 10M parallel loop takes 220 seconds. That's because with the default settings, the Parallel.For() method creates 81 threads in my machine. That's a lot of overhead. But if I limit it to only 3 or 4 threads, it performs a lot better. You should not blindly follow parallelism everywhere you can. Performance of CPU bound and I/O bound works differ vastly when using these techniques (I/O bound works usually always output better performance for this).

  • @Fortwuny
    @Fortwuny 11 ปีที่แล้ว

    thank you for this explanation!!!!

  • @manjeetnandal1
    @manjeetnandal1 5 ปีที่แล้ว

    Nice. Many thanks!

  • @tejashreemadake9243
    @tejashreemadake9243 3 ปีที่แล้ว

    Confused..!!! may sound stupid but if our laptops have single processor then how does it make any difference whether we are using threading or task, because all we have is single processor right??

  • @KDOERAK
    @KDOERAK 10 ปีที่แล้ว

    thank you for this great video, very well done!

  • @PraveenKumar-ft2kr
    @PraveenKumar-ft2kr 7 ปีที่แล้ว

    Excellent 👌👌

  • @shootdaj
    @shootdaj 11 ปีที่แล้ว

    Where is the 2nd part of this video? I cannot seem to find a link for it. Thanks.

    • @shashikantrajak1784
      @shashikantrajak1784 5 ปีที่แล้ว +1

      I think these are paid videos. This video might be only for advertisement prapose.

  • @akhilsreekumar9848
    @akhilsreekumar9848 4 ปีที่แล้ว

    I used parallel.foreach for filling a model but it is not filling correctly.....

  • @MohitAgarwalSongs
    @MohitAgarwalSongs 6 ปีที่แล้ว

    Good one 👍🏻

  • @fordfiveohh
    @fordfiveohh 9 ปีที่แล้ว

    If you spawn two or more threads manually it will parallelize but you will need callbacks unless its fire and forget.

    • @dnfvideo
      @dnfvideo  9 ปีที่แล้ว

      +fordfiveohh For technical query mail us at questpond@questpond.com

  • @ANCIENTASTRONAUT
    @ANCIENTASTRONAUT 8 ปีที่แล้ว

    great video,

  • @8uddishh
    @8uddishh 11 ปีที่แล้ว +1

    you should have put the parallel for inside the run million iterations... technically you are showing two diff examples.....

  • @RashmiPurbey
    @RashmiPurbey 9 ปีที่แล้ว

    video for mutex semaphore, semaphoreslim is missing in questpond.com. Pls put it back

    • @dnfvideo
      @dnfvideo  9 ปีที่แล้ว

      +Rashmi Purbey
      Hello Mam,
      The video is there you can see C# Threading Q & A Videos section in questpond

    • @roietrip
      @roietrip 9 ปีที่แล้ว

      +.NET Interview Preparation videos
      couldn't find it also, not on your TH-cam channel or questpond.com

  • @sadam4siyal485
    @sadam4siyal485 6 ปีที่แล้ว

    Good video

  • @MeenakshiSekar
    @MeenakshiSekar 11 ปีที่แล้ว

    not able to access this video. it says an error occurred

  • @Obaidkhan916
    @Obaidkhan916 8 ปีที่แล้ว +3

    P2(intel Pentium 2) is single core btw

  • @surajfrommumbai
    @surajfrommumbai 11 ปีที่แล้ว

    Its a dope video awesome.

  • @ericn6463
    @ericn6463 6 ปีที่แล้ว

    Is this code not doing 1 million * RunMillionIterations() I think you can drop the one of the for... probably the one inside RunMillionIterations

  • @ajeshmahto3091
    @ajeshmahto3091 10 ปีที่แล้ว +1

    how to implement, below code using TPL. Any Idea?
    foreach (GridViewRow row in grdSearch.Rows)
    { //do smth
    }

    • @satishb6226
      @satishb6226 4 ปีที่แล้ว

      Using parallel foreach

  • @ultrastoat3298
    @ultrastoat3298 7 ปีที่แล้ว

    The explanation here is not correct. He took a single threaded "for loop" and placed it on a single thread. Well, that is in fact multi threading. Your fist thread is the thread of your application itself. The second thread is the "for loop", for a total of 2 threads. What you are really talking about is parallelizing work that is "normally" single threaded, which is distinctly different.

  • @tzvigo1
    @tzvigo1 6 ปีที่แล้ว

    In the first example you run a single thread and in the second you run MANY threads

  • @sayedreda3982
    @sayedreda3982 8 ปีที่แล้ว

    Where is the second part of TPL video?

    • @manpreet4all
      @manpreet4all 7 ปีที่แล้ว

      I think you need to purchase his subscription for 2nd part ;-)
      From questions.com

  • @jasraj29
    @jasraj29 11 ปีที่แล้ว

    awesome..

  • @knitinr
    @knitinr 11 ปีที่แล้ว

    It plays for me. Must have been just a TH-cam error.

  • @hussainhaydari
    @hussainhaydari 5 ปีที่แล้ว

    Please set your second video here

  • @imhassane
    @imhassane ปีที่แล้ว

    Can someone clear a confusion for me ?
    Isn't he running the millions iterations in only one thread ? I thought he would create a thread for each iteration.

  • @vaibhavmaurya9685
    @vaibhavmaurya9685 2 ปีที่แล้ว

    An Interviewers asked me : Can you create 50 threads using TPL ? What would be my answer ?

  • @hpeterh
    @hpeterh ปีที่แล้ว

    I think this demonstration is not a good example, it is confusing and partially fundamentally wrong. You can only parallelize a loop, when the next result does not depend from the previous result. For example, when you process lines of an image.
    This program does not parallelize the job, it runs the same job manifold, which has no sense. Of course it shows that the workload is well distributed, but programmatical this has no sense.
    The first example will of course not accelerate the calculation. It will however free the main thread from the workload, so that the user interface stays fluid and responsive.

  • @EliCDavis
    @EliCDavis 3 ปีที่แล้ว

    My dude you just ran 250000000000 iterations per core.

  • @MD-vs9ff
    @MD-vs9ff ปีที่แล้ว

    This is an extremely poorly made example.
    First, The for loop you start with CANNOT be parallelized as it is written, because the result of each iteration depends on the result of the previous iteration. It must run sequentially.
    Second, your "rewrite" is not splitting up the work of the original function and running half of it on each core. Instead, you are running the entire function 1,000,000 times (with the full lop done each time), with half of the calls running on each processor. You have not parallelized the original problem at all, you've just multiplied it.

  • @gauravtarey
    @gauravtarey 10 ปีที่แล้ว +1

    P8, hehehe :p

  • @MikeStock88
    @MikeStock88 2 ปีที่แล้ว

    another excellent explanation, thanks for sharing

  • @dcpkumar
    @dcpkumar 11 ปีที่แล้ว

    thank you for this explanation!!!!