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
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 !
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.
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?
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!
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?
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.
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));"
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?
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 ./*
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 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++)
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?
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.
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!
thank you so much for the video, hope to study more on thread synchronization, thread pool and how they are implemented in C++
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
Thanks! Check this out: ua-cam.com/video/jwJ4Eh_2Umo/v-deo.html
i guess Im kinda off topic but do anyone know a good site to watch new series online?
Awesome recap of multi-threading, using this to review over my OS class after graduation.
Thank you for such a great introduction to multithreading from basics, crystal clear notes and awesome examples! 🙏
Excellent tutorial! Nice introduction to different aspects of multithreading with simple examples!
Great video, Please make more! They are short and informative and a great learning resource
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 !
11:02: Shouldn't the AccumulateFunctors pointers in the threads vector be released using delete at the end of execution to avoid leaking memory?
Great video! It was very comprehensive and easy to understand.
Glad it was helpful!
Hey Arash! Nice video :) Thanks for posting such an amazing video - Nakul
Thank you Arisaif! Great Video!
Awesome! Liked and subscribed, really straightforward and clear!
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.
Thank you for this useful video, hope to see the next video!!!
Hope you are having a great Summer! Check this out: ua-cam.com/video/jwJ4Eh_2Umo/v-deo.html
Really high quality, excellent explanation!
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?
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!
Thanks! Check this out: ua-cam.com/video/jwJ4Eh_2Umo/v-deo.html
im getting a problem where my compiler does not recognized and suggests me that I should #include its header which I already did
Excellent course! Thanks.
github link has no any code related to Multithreading in cpp. Can you please check.
Please check here: github.com/ourarash/cpp_tour/tree/master/src/multi_threading
Try this updated repo: github.com/ourarash/multithreading_cpp
Great video! one question, how can I use thread and MPI together? could you make a video of that. Thank you
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?
Thank you ! Can you please create topic-wise playlists e.g. C++, Javascript, etc. too. Would be quite helpful 🙏
Sure, thanks for the suggestion!
@@arisaif Thanks for quick response 👍
It would be great if you'd create the playlists, especially for C++, asap 🙂
Great job!
Thanks, very helpful!
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?
The code doesn't compile if we used raw pointer or smartpointer instead of the object they point to. Idk why.
Very nicely explained. Thanks!
Glad it was helpful!
Amazing work, thank you for the video.
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.
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));"
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?
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 ./*
Please make more content on C++
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?
Glad you liked the video. Can you tell me where in the video you are referring to?
@@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++)
Thanks dude this help me a lot
Glad it helped!
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?
Awesome
Thank you! Subscribed!
Thanks for the sub!
Good job
Thank you so much
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.
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!
Great video
Easy to understand
my code says std not a name type
I think you are not including the right header files.
@@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.
Great 🎉
You should take easy examples to explain the concepts.