- Timestamp:
- Mar 19, 2019, 4:30:33 PM (6 years ago)
- 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
- Location:
- doc/papers/concurrency/c++-cor
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/c++-cor/C++Cor-ts.cpp
rbe3416d r8f936bf 18 18 //================================================== 19 19 20 21 20 co_yield i; 22 21 … … 28 27 29 28 co_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 4 4 struct fmt_cor { 5 5 struct promise_type { 6 char * _value = nullptr; 6 char _value; 7 int g, b; 7 8 8 9 fmt_cor get_return_object() { … … 11 12 12 13 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; 15 25 } 16 26 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(); 22 29 } 23 24 void unhandled_exception() {} 30 char await_resume() noexcept { 31 assert(_promise); 32 return _promise->_value; 33 } 25 34 }; 26 35 … … 52 61 53 62 void send(char a) { 54 assert(_coroutine.promise()._value); 55 *_coroutine.promise()._value = a; 63 _coroutine.promise()._value = a; 56 64 _coroutine.resume(); 57 65 } … … 59 67 60 68 fmt_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(); 63 71 for(;;) { 64 72 for(g = 0; g < 5; g++) { 65 73 for(b = 0; b < 4; b++) { 66 co_yield c; 67 std::cout << c; 74 std::cout << co_await fmt_cor::get(); 68 75 } 69 76 std::cout << " ";
Note: See TracChangeset
for help on using the changeset viewer.