std future and std promise
suggest changeThe following example sets a promise to be consumed by another thread:
#include <future>
#include <iostream>
#include <string>
#include <thread>
int main()
{
auto promise = std::promise<std::string>();
auto producer = std::thread([&]
{
promise.set_value("Hello World");
});
auto future = promise.get_future();
auto consumer = std::thread([&]
{
std::cout << future.get();
});
producer.join();
consumer.join();
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents