Changeset 8f936bf


Ignore:
Timestamp:
Mar 19, 2019, 4:30:33 PM (5 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
79b018f3
Parents:
be3416d
Message:

Got rid of weird yield in fmt example

Location:
doc/papers/concurrency/c++-cor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/concurrency/c++-cor/C++Cor-ts.cpp

    rbe3416d r8f936bf  
    1818//==================================================
    1919
    20 
    2120co_yield i;
    2221
     
    2827
    2928co_await __promise.yield_value(i);
     29
     30//==================================================
     31
     32... coroutine() {
     33        __coroutine_context* __context = new __coroutine_context{};
     34        __return = __context->_promise.get_return_object();
     35        co_await   __context->_promise.initial_suspend();
     36
     37        ...
     38
     39__final_suspend_label:
     40        co_await __context->promise.final_suspend();
     41        delete __context;
     42}
  • doc/papers/concurrency/c++-cor/fmt.cpp

    rbe3416d r8f936bf  
    44struct fmt_cor {
    55        struct promise_type {
    6                 char * _value = nullptr;
     6                char _value;
     7                int g, b;
    78
    89                fmt_cor get_return_object() {
     
    1112
    1213                auto initial_suspend() { return suspend_never(); }
    13                 auto final_suspend()   {
    14                         return suspend_always();
     14                auto final_suspend()   { return suspend_always(); }
     15
     16                void return_void() {}
     17                void unhandled_exception() {}
     18        };
     19
     20        struct get {
     21                promise_type * _promise = nullptr;
     22
     23                bool await_ready() noexcept {
     24                        return false;
    1525                }
    1626
    17                 void return_void() {}
    18 
    19                 auto yield_value(char & value) {
    20                         _value = &value;
    21                         return suspend_always();
     27                void await_suspend(std::experimental::coroutine_handle<promise_type> _coroutine) noexcept {
     28                        _promise = &_coroutine.promise();
    2229                }
    23 
    24                 void unhandled_exception() {}
     30                char await_resume() noexcept {
     31                        assert(_promise);
     32                        return _promise->_value;
     33                }
    2534        };
    2635
     
    5261
    5362        void send(char a) {
    54                 assert(_coroutine.promise()._value);
    55                 *_coroutine.promise()._value = a;
     63                _coroutine.promise()._value = a;
    5664                _coroutine.resume();
    5765        }
     
    5967
    6068fmt_cor Fmt() {
    61         char c;
    62         int g, b;
     69        int g; // = co_await fmt_cor::g();
     70        int b; // = co_await fmt_cor::b();
    6371        for(;;) {
    6472                for(g = 0; g < 5; g++) {
    6573                        for(b = 0; b < 4; b++) {
    66                                 co_yield c;
    67                                 std::cout << c;
     74                                std::cout << co_await fmt_cor::get();
    6875                        }
    6976                        std::cout << "  ";
Note: See TracChangeset for help on using the changeset viewer.