mercredi 26 septembre 2018

std::future.get() is invalid exit

i'm remove future.get() then problem arose. Code is here

void WaitingForWorkByFuture(std::future<void>&& fut)
{
    std::cout << "Worker : Waiting for work." << std::endl;
    fut.wait();
    std::cout << "Complete Work" << std::endl;
}

void SetDataReady(std::promise<void>&& prom)
{
    std::cout << "Data is Ready" << std::endl;
    //prom.set_value();
}

void main()
{
    std::promise<void> ready;
    auto fut = ready.get_future();

    std::thread t1(WaitingForWorkByFuture, std::move(fut));
    std::thread t2(SetDataReady, std::move(ready));

    t1.join();
    t2.join();

    return;
}

May I know what am I wrong and how to fix it?

Many thanks.

Aucun commentaire:

Enregistrer un commentaire