I got an exception when using a future and a promise in the same thread, while using c++20.
The exception is throwed when prom.set_value(111);
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
#include <future>
#include <iostream>
int main() {
std::promise<int> prom;
std::future<int> fut = prom.get_future();
std::cout << "1 ok" << std::endl;
prom.set_value(111);
std::cout << "2 ok" << std::endl;
std::cout << fut.get() << std::endl;
return 0;
}
Run the above code on https://onlinegdb.com/gZp3cOOvj