logoalt Hacker News

lukaslalinsky • today at 6:47 PM • 1 reply • view on HN

I think you are misunderstanding what the article suggests. std::atomic::wait and std::atomic::notify_all are the C++ abstractions over futexes. The whole concept of the future can be expressed in terms of atomics and futexes. The only problem is that the C++ standard doesn't have std::atomic::wait_for.


Replies

gsliepen • today at 7:06 PM

You can indeed, but it would change the code from the article drastically: you have to get rid of the mutex, the discriminant becomes an atomic variable, and you need barriers between access to the discriminant and to the value the source is holding. Performance-wise I don't think it will show a drastic improvement, the main benefit would be the size of the source.