logoalt Hacker News

C++ futures part 1: The mental model

59 points • by ibobev • last Monday at 6:05 PM • 12 comments • view on HN

Comments

gsliepen • today at 4:57 PM

> The wait_for method is why we have a condition variable at all. If it weren’t for that guy, we could have used std::atomic‘s wait and notify_all methods.

No, the std::mutex is the reason you have a condition variable. Never mix std::atomic with std::mutex-and-friends, you are very likely introducing race conditions that way.

➕ show 2 replies
ahartmetz • today at 2:51 PM

This seems to omit the main point of it, though? That the compiler turns a function into a state machine that can restart from any of its suspension points. I guess that's the "state" variable, but what I'm talking about is what it contains and the partially compiler-generated code that deals with it.

C++ async is unfortunately a "bring your own runtime" sort of model (for now), but it does handle the part that would be incredibly tedious by hand, building above mentioned state machine.

➕ show 4 replies
thefourthchime • today at 3:27 PM

Wow, I had no idea Raymond Chen was still doing blog posts. I used to love his posts back in the day.

➕ show 1 reply