GoingNative 39: await/coroutines

Sign in to queue

Description

Embed

Download

Download this episode

The Discussion

  • User profile image
    petke79

    Nice presentation.

    When I first heard about "await", I mistakenly thought it was very ugly that we would be adding a keyword to the language (await) that is hard coded to depended on a library type (std::future). That seemed backwards. Now I learned that its not that bad. Await is not hardcoded to the std::future type but is more general than that. If a better std::future is invented in the future (pun). It will work with that also.

    On a lighter note. I like the wallpaper. Where can I get that? It looks algorithmic, similar to Roger Penrose's non repeating tiling patterns.

  • User profile image
    gha11

    @petke79: Thanks for the kind words and for watching! If you really want to know, I'll try to find out for you ;) Email me at gaha at microsoft!

  • User profile image
    Ivan

    Hi, do you have some full example code for expected<int> and await example?
    I am curious how the full code looks.

  • User profile image
    GorNishanov

    For await, look at the examples in awaitable section starting 32. In particular, slide 44 how to write an await adapter to call OS APIs directly bypassing any intermediaries such as futures or tasks.

    https://github.com/boostcon/cppnow_presentations_2015/raw/master/files/CppNow2015_Coroutines_in_C++17.pdf

    Expansion for expected would look something like this (it will be enabled in 2015 VS Update 1, RTM does not support it):

    template <typename T> bool await_ready(expected<T> & e) { return e.has_value(); }

    template <typename T> T& await_resume(expected<T> & e) { return e.value(); }

    template <typename T, typename P> 
    void await_suspend(expected<T> & e, coroutine_handle<P> & p) {
        p.set_error(e.error());
    }

     

     

  • User profile image
    Ivan

    Tnx Gor.

  • User profile image
    Chabster

    The following simple app triggers breakpoint several times (int 3 instruction). Then just hangs.

    Is this feature working in 2015 RTM?

    #include <experimental\generator>
    #include <future>

    using namespace std;
    using namespace std::experimental;

    future<int> get_int()
    {
    return async([] { return 0; });
    }

    future<int> wait_int()
    {
    return __await get_int();
    }


    int main()
    {
    auto const i = wait_int().get();
    return 0;
    }

  • User profile image
    GorNishanov

    @Chabster:

    Can you double check that you don't have /ZI (Edit and Continue Debugging) switch on?

    It is in project properties | C/C++ | General | Debug Information Format.

    Please switch to /Zi (small i). Edit and continue debugging codegen is not compatible at the moment with coroutines.

Add Your 2 Cents