#include <atomic>
#include <thread>
#include <iostream>
#include <future>
#include <syncstream>
std::atomic<int> g_cnt = 0;
void log(const char* str)
{
std::osyncstream ss(std::cout);
ss << str << std::endl;
}
void worker1(std::future<int> fut)
{
log("this is thread 1");
g_cnt++;
fut.get();
log("thread 1 exists");
}
void worker2(std::promise<int> prom)
{
log("this is thread 2");
g_cnt++;
prom.set_value(10);
log("thread 2 exists");
}
int main()
{
std::promise<int> prom;
std::future<int> fut = prom.get_future();
// Fire the 2 threads:
std::thread t1(worker1, std::move(fut));
std::thread t2(worker2, std::move(prom));
t1.join();
t2.join();
log("main exists");
}