Learn C++ Multi Threading in 20 Minutes

Поділитися
Вставка
  • Опубліковано 24 січ 2025

КОМЕНТАРІ • 70

  • @tiemingsun7375
    @tiemingsun7375 4 роки тому +10

    thank you so much for the video, hope to study more on thread synchronization, thread pool and how they are implemented in C++

  • @elliedunstan728
    @elliedunstan728 4 роки тому +8

    This is fantastic. Video(s) on thread synchronisation and thread pools would be super helpful! I like that you do summaries after each concept introduced. If you have any extra material that you recommend viewers take a look at that would be great too :) thank you

    • @arisaif
      @arisaif  4 роки тому

      Thanks! Check this out: ua-cam.com/video/jwJ4Eh_2Umo/v-deo.html

    • @rudykevin2959
      @rudykevin2959 3 роки тому

      i guess Im kinda off topic but do anyone know a good site to watch new series online?

  • @iamdriy
    @iamdriy 2 роки тому

    Awesome recap of multi-threading, using this to review over my OS class after graduation.

  • @vaibhavpurdue
    @vaibhavpurdue 2 роки тому +3

    Thank you for such a great introduction to multithreading from basics, crystal clear notes and awesome examples! 🙏

  • @abhishek.goudar
    @abhishek.goudar 2 роки тому +1

    Excellent tutorial! Nice introduction to different aspects of multithreading with simple examples!

  • @MrBoBiNaToR1000
    @MrBoBiNaToR1000 4 роки тому +3

    Great video, Please make more! They are short and informative and a great learning resource

  • @kanhaglobal
    @kanhaglobal 3 роки тому

    Very Helpful coverage of the C++ Multi Threading in 20 minutes video with Examples and Summaries. Thanks for sharing your expertise on this topic. Great Work !

  • @djsixottawa
    @djsixottawa Рік тому

    11:02: Shouldn't the AccumulateFunctors pointers in the threads vector be released using delete at the end of execution to avoid leaking memory?

  • @avergreenie
    @avergreenie 2 роки тому +2

    Great video! It was very comprehensive and easy to understand.

    • @arisaif
      @arisaif  2 роки тому +1

      Glad it was helpful!

  • @anukulappltv9985
    @anukulappltv9985 2 роки тому

    Hey Arash! Nice video :) Thanks for posting such an amazing video - Nakul

  • @АндрейБорисов-и4о
    @АндрейБорисов-и4о 3 роки тому +1

    Thank you Arisaif! Great Video!

  • @kristijanceple6026
    @kristijanceple6026 4 роки тому +1

    Awesome! Liked and subscribed, really straightforward and clear!

  • @thestarinthesky_
    @thestarinthesky_ Рік тому

    I found the multithreading tutorial to be very helpful, and the included examples were particularly effective in reinforcing my understanding (they are really practical). Thank you so much.
    I have two questions about the code shown @11:08 in the video:
    1) Why did you use a raw pointer instead of a shared pointer? (I like raw pointers better by the way :) just wanted to know why)
    2)I noticed that you used the new operator, which I've learned can cause a lot of overhead, especially when called repeatedly in a loop. I think it is possible to create a std::vector of AcumulateFunctor objects (vectSum) and pass each element as an argument to workers.emplace_back(std::ref(vectSum.at(index)), start, end); in a loop instead (I tried and worked)
    By the way, I took an optimized C++ course and learned that using malloc instead of new can result in much lower overhead.

  • @binlingsu144
    @binlingsu144 4 роки тому +2

    Thank you for this useful video, hope to see the next video!!!

    • @arisaif
      @arisaif  4 роки тому

      Hope you are having a great Summer! Check this out: ua-cam.com/video/jwJ4Eh_2Umo/v-deo.html

  • @bla7091
    @bla7091 3 роки тому

    Really high quality, excellent explanation!

  • @TimCrinion-j2r
    @TimCrinion-j2r Рік тому

    Is there a name for these functions such as cin or wait() or join() or get() that have to wait for something else to happen before you can start the line below?

  • @mihir777
    @mihir777 4 роки тому +5

    Awesome presentation. Thank you for making it so easy to understand. It helped when you said don't get scared, future is just a return type. Please make the next set of videos. If there is a donation link, let us know as well. Thank you!

    • @arisaif
      @arisaif  4 роки тому

      Thanks! Check this out: ua-cam.com/video/jwJ4Eh_2Umo/v-deo.html

  • @josecastellanosargueta7370
    @josecastellanosargueta7370 2 роки тому

    im getting a problem where my compiler does not recognized and suggests me that I should #include its header which I already did

  • @aliasadian520
    @aliasadian520 Рік тому

    Excellent course! Thanks.

  • @pradeepkumarpatil8050
    @pradeepkumarpatil8050 4 роки тому +2

    github link has no any code related to Multithreading in cpp. Can you please check.

    • @arisaif
      @arisaif  4 роки тому

      Please check here: github.com/ourarash/cpp_tour/tree/master/src/multi_threading

    • @arisaif
      @arisaif  4 роки тому

      Try this updated repo: github.com/ourarash/multithreading_cpp

  • @dankusanovic
    @dankusanovic 4 роки тому +2

    Great video! one question, how can I use thread and MPI together? could you make a video of that. Thank you

  • @johetajava
    @johetajava 3 роки тому

    Why do you need a reference to a pointer? Why would the functor be passed by value if there is no value, just a pointer in the functor variable?

  • @abhishek.chakraborty
    @abhishek.chakraborty 4 роки тому +5

    Thank you ! Can you please create topic-wise playlists e.g. C++, Javascript, etc. too. Would be quite helpful 🙏

    • @arisaif
      @arisaif  4 роки тому

      Sure, thanks for the suggestion!

    • @abhishek.chakraborty
      @abhishek.chakraborty 4 роки тому

      @@arisaif Thanks for quick response 👍
      It would be great if you'd create the playlists, especially for C++, asap 🙂

  • @TheAsimo1
    @TheAsimo1 4 роки тому +2

    Great job!

  • @ГерриПитт
    @ГерриПитт 4 роки тому +2

    Thanks, very helpful!

  • @Dead2098
    @Dead2098 2 роки тому

    And why do we do std::ref(*functor) and not just functor? functor is already a pointer, right, so why do we create a new pointer for the same memory address?

    • @danielkarpati3196
      @danielkarpati3196 2 роки тому

      The code doesn't compile if we used raw pointer or smartpointer instead of the object they point to. Idk why.

  • @CriticRoshun
    @CriticRoshun 3 роки тому

    Very nicely explained. Thanks!

    • @arisaif
      @arisaif  3 роки тому

      Glad it was helpful!

  • @isaacgp4470
    @isaacgp4470 3 роки тому

    Amazing work, thank you for the video.

  • @Uceline8070
    @Uceline8070 2 роки тому

    Thank you for the interesting video. You have a bug though. The answer should be of the form of (5*....*5*...*) where the stars are the zeros based on your max number of elements. In your case 8 zeros in before and after the second 5. your bug comes from how you have defined your threads. It should be (from 0 to step for thread 1, and then from step+1 to the end for thread two). You are missing the +1 in the second thread.

    • @Uceline8070
      @Uceline8070 2 роки тому

      The same is true when you do it for ten threads:
      the for loop should be modified to "Threads.push_back(std::thread(AddTheRang, std::ref(PSum[i]), i*step +1 , (i+1)*step));"

  • @xenoxel
    @xenoxel 3 роки тому

    I downloaded the files and imported them into VS code, however when I try to run the code I get namespace "std" has no member "thread" can you explain to me how I can avoid this error, perhaps you could point me to or link to a tutorial?

    • @arisaif
      @arisaif  3 роки тому

      The provided repo should work, but sounds like C++11 (and higher) libraries that include thread are not found on your system for some reason. You may want to try this command to see if it works:
      *g++ -std=c++17 -lpthread src/main/**main.cc** -I ./*

  • @interested_in_everything
    @interested_in_everything 2 роки тому

    Please make more content on C++

  • @siedamout3904
    @siedamout3904 4 роки тому +1

    Hey Arisaif, thanks for the superb explanation. But I have a question. In your functors example, you allocate a memory but I do not see if the memory is released. Wouldn't it create a memory leak?

    • @arisaif
      @arisaif  4 роки тому

      Glad you liked the video. Can you tell me where in the video you are referring to?

    • @siedamout3904
      @siedamout3904 4 роки тому

      ​@@arisaif in AccumulateFunctor *functor = new AccumulateFunctor , isn't memory allocated? if yes, then doesn't it need to be released at some point to avoid memory leak? (or maybe I am missing something in the video or I could be wrong as I am quite new to C++)

  • @LinhLinh-ze6el
    @LinhLinh-ze6el 2 роки тому

    Thanks dude this help me a lot

    • @arisaif
      @arisaif  2 роки тому

      Glad it helped!

  • @minzhou1895
    @minzhou1895 3 роки тому

    Thank you Ari! Very helpful video. In the example that we want to return a number, when we use std::async and functor, does the overload operator () returns a value?

  • @sunnycheung3580
    @sunnycheung3580 4 роки тому +3

    Awesome

  • @vasquezitosanchezito
    @vasquezitosanchezito 4 роки тому

    Thank you! Subscribed!

    • @arisaif
      @arisaif  4 роки тому

      Thanks for the sub!

  • @muhammadshehzad5785
    @muhammadshehzad5785 4 роки тому +2

    Good job

  • @amrtcpp6203
    @amrtcpp6203 4 роки тому +1

    Thank you so much

  • @volodymyrkorniichuk1164
    @volodymyrkorniichuk1164 4 роки тому +1

    There is no information about execution policies for std::async in this video. And without it your samples for std::async in some cases can all run in single thread and people will wonder why.

    • @arisaif
      @arisaif  4 роки тому

      That is correct, I wanted this to be a quick introduction without going into details. By not specifying std::launch policy, the function will use the automatic launch policy which means that it is up to the implementation to chose the policy, i.e. there is a chance that the implementation choses std::launch::deferred policy which will run the function in a single thread. Using std::launch::async will guarantee that the function will run in a separate thread.
      I add this link for anyone that wants to read further: en.cppreference.com/w/cpp/thread/async
      Thanks for mentioning this!

  • @vorche_
    @vorche_ 2 роки тому

    Great video

  • @6733199
    @6733199 Рік тому

    Easy to understand

  • @ixcus
    @ixcus 2 роки тому

    my code says std not a name type

    • @arisaif
      @arisaif  2 роки тому

      I think you are not including the right header files.

    • @ixcus
      @ixcus 2 роки тому

      @@arisaif yes you are right I got more into coding c++ and I noticed I didn’t know some of the basics yet.. thanks again.

  • @techs9994
    @techs9994 Рік тому

    Great 🎉

  • @Rocky26rocky
    @Rocky26rocky 2 роки тому

    You should take easy examples to explain the concepts.