Launching multiple std::thread in C++ | Introduction to Concurrency in Cpp

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

►Lesson Description: In this lesson we learn about creating our first modern C++ threaded application. We learn about how to launch a thread and properly join a thread. The 'join' is a way to synchronize how the threads execute, and which thread will be blocked. A visual explanation is also provided to help comprehend how a thread is executing.

00:00 Launching multiple threads from a vector
1:50 returning the executing thread id
3:26 Sequential execution as a result of bad join
4:50 Launching threads for parallel execution

►Please like and subscribe to help the channel!
Рекомендации по теме
Комментарии
Автор

If you are on Windows, threads will not reuse the same id of a thread that was recently destroyed. You will see different ids for each thread, in the example where the join occurs in the same for loop as when the thread is created.

nedmac
Автор

Thank you Mike Shah for this free online course.

konstantinrebrov
Автор

4:13 i have this code and i have different threads(Win64, gcc, i5-9400f)(when threads.push_back(function); threads[i].join() in one *for*) WHY??? I don't understand this moment

brunner
Автор

Hey Mike, great video!! Just wondering as threads are pushed into a vector and it exceeds it's capacity, wouldn't deep copy of threads occur which would launch end up creating more than 10 threads and thus executing more instances of the lambda function?

MrSals
Автор

Hey Mike, great series!
What I really don't understand is why you expect and especially get the same thread!
1. I create a thread, pass a value, it gets printed with the thread id and gets joined.
2. I create the second thread and everything repeats itself.
How can it be, that you always get the same thread, when 10 are created and joined?!

rombrandsdg
Автор

why not emplace_back?, i thought std::vec does a copy when you push_back

ather
Автор

Keep it going man, you are awesome!
Greetings from Croatia!

gvberhveh
Автор

this entrire playlist is really helpful. Thanks

punitkumarojha
Автор

very intuitive example and nice explanation.

sanjaygatne