How to use multithreading in C++

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

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

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

    This video is great, it's much better than most tutorials I could find online. My program runs 1.4x faster using multithreading!

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

      Nice, that's a great boost to speed!

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

    You do not need to use packaged_task, you can just pass a lambda to std::thread, std::thread thread([]() { // code here }));

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

    Seems like you have a duplicate video starting around 16:13. Also, it would be cool to show a big feature of multithreading, which is rather than waiting for the calculation to complete every update loop, starting it in the background and polling whether it has finished or not. This would give an even bigger performance gain. Great video nonetheless!

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

      Yes true. I wanted this example to be as easy as possible.
      Thank you for the hint of the cutting. I‘m still really new to video editing and am struggling with the software. I will recut and upload as soon as I find the time.

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

    why do we have performance gain in multithreaded versions in the first place? i mean, task is moved to other thread, but we still have to wait for them to finish, thread.join() is blocking, isn't it? so, logically, it should be even slower because of thread creation overhead, i am confused

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

      Good observation! We see the performance gain because there are two threads that are created in parallel. Thats why its only beneficial if there are at least two tasks which need to be computed. If we would only create a single thread we see a (small) drop in performance .

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

      @@ZenSepiol ah, somehow completely ignored that we had two tasks, now its clear 😀 thanks

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

    I want to draw the ui in parallel in imgui, is it possible? Means do not wait for operation to complete, whenever info is available then draw, until then continue to draw frames

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

      Yes, it is possible but a little more complex than what is shown. You need to create a thread, detach it and use a buffer to retrieve the data from the thread. Probably, I'll do a video about that in the future and extend the App Framework.

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

      @@ZenSepiol Thank you so much, would be waiting for that :)