std::future and std::async in Modern cpp | Introduction to Concurrency in C++

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

►Lesson Description: In this lesson I teach you std::async and the idea that it returns a future. We block on the futures result if we need to compute the result, and otherwise std::async is an easy way to launch threads.

00:00 Introduction to std::async
1:11 What is a future
2:02 Creating a std::async function
3:27 Retrieving result with get
4:00 What is the point of async?
5:29 Waiting on a futures result
6:00 Progress is made in background on a task

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

As a second year student of CS who's having this the next week in his programming classes - thank you very much! You made it easily understandable

arkadiuszuanowski
Автор

Async programming in c++ making sense to me now sir. Thanks a lot ❤

HowlingDeath
Автор

Hey amazing tutorial! Made it so simple! I can finally get a simple understanding on writing coroutines in C++! Keep up the good work! :)

purpletom_yt
Автор

Kind of wondering about that example. It doesn't really show the benefit of async calls really because get appears to lock the system up.
For instance, say I request some network data using an async call. I would like the data right away, but I have other tasks I can do if it's going to take a while for the data to come in.
So, can I check the future in a non blocking fashion to see if it has gotten the data and move onto other tasks and just check in periodically.
Or is it supposed to work like you make an async call to request the network data, then make async calls to carry out other tasks, then call get, which blocks this thread, but the other tasks will work independently while the main thread stays stuck on the get call until the network data comes in?

haddow
Автор

Keep up the good work,
Love your vids
By the way I was watching your SDL playlist by i got stuck trying to install and set up SDL2_TTF mingw32 on windows do you have any advice on how i could set it up.

williamchidiac
Автор

Is std::async a better solution than creating a threadpool implentation for a client server model, where the server spins a new thread or call async for every client ? I was wondering about the implementation of std::async .

semimaths
Автор

isn't this overall better than spooling threads with std::thread? We are reusing threads which reduce overhead cost

WillJ-jytl
Автор

So the way I understood this, std::future /std::async is primarily used to perform return operations on a different thread, while std::thread is being used for independed work. Did I get this right?

NorthstriderGaming
Автор

Hi Mike, thanks for your tutorial. However I still struggle to understand the advantage of 'async' instead of regular threads. Is it all about handling/retrieving 'futures'? Or is it about geting rid of threadpool in applications that run large amount of threads?

nighttime
Автор

The actual execution of the async function happened at the time of the future is defined, or at the get?

edmondw