- Timestamp:
- Mar 20, 2019, 3:42:24 PM (5 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:
- 709e0e0
- Parents:
- 13b1b1d
- Location:
- doc/papers/concurrency/examples
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/Fib.cpp
r13b1b1d r571bf75 1 #include "base.hpp"2 3 1 #include <algorithm> 2 #include <iostream> 4 3 #include <iterator> 5 4 #include <vector> 5 6 #include <experimental/coroutine> 6 7 7 8 template<typename T> … … 14 15 } 15 16 16 auto initial_suspend() { return s uspend_always(); }17 auto final_suspend() { return s uspend_always(); }17 auto initial_suspend() { return std::experimental::suspend_always(); } 18 auto final_suspend() { return std::experimental::suspend_always(); } 18 19 19 20 void return_value(T value) { … … 23 24 auto yield_value(T value) { 24 25 _value = value; 25 return s uspend_always();26 return std::experimental::suspend_always(); 26 27 } 27 28 -
doc/papers/concurrency/examples/Format.cpp
r13b1b1d r571bf75 1 2 #include "base.hpp"1 #include <iostream> 2 #include <experimental/coroutine> 3 3 4 4 struct fmt_cor { 5 5 struct promise_type { 6 6 char _value; 7 struct locals {8 int g, b;9 } * _l;10 7 11 8 fmt_cor get_return_object() { … … 13 10 } 14 11 15 auto initial_suspend() { return s uspend_never(); }16 auto final_suspend() { return s uspend_always(); }12 auto initial_suspend() { return std::experimental::suspend_never(); } 13 auto final_suspend() { return std::experimental::suspend_always(); } 17 14 18 15 void return_void() {} 19 16 void unhandled_exception() {} 20 21 auto yield_value(locals & l) {22 _l = &l;23 return suspend_never();24 }25 17 }; 26 18 … … 50 42 if(_coroutine) { 51 43 _coroutine.destroy(); 52 if (_coroutine.promise()._l->g != 0 | _coroutine.promise()._l->b != 0) { 53 std::cout << "\n"; 54 } 44 55 45 } 56 46 } … … 79 69 80 70 fmt_cor Fmt() { 81 fmt_cor::promise_type::locals l; 82 co_yield l; 71 struct locals { 72 int g, b; 73 74 ~locals() { 75 if (g != 0 | b != 0) { 76 std::cout << "\n"; 77 } 78 } 79 } l; 83 80 for(;;) { 84 81 for(l.g = 0; l.g < 5; l.g++) { -
doc/papers/concurrency/examples/counter.cpp
r13b1b1d r571bf75 1 #include "base.hpp" 1 #include <iostream> 2 #include <experimental/coroutine> 2 3 3 4 struct counter_cor { … … 7 8 } 8 9 9 auto initial_suspend() { return s uspend_never(); }10 auto final_suspend() { return s uspend_never(); }10 auto initial_suspend() { return std::experimental::suspend_never(); } 11 auto final_suspend() { return std::experimental::suspend_never(); } 11 12 12 13 void return_void() {} … … 47 48 std::cout << "Counter: called\n"; 48 49 for(unsigned i = 1;; i++) { 49 co_await s uspend_always{};50 co_await std::experimental::suspend_always{}; 50 51 std::cout << "Counter: Resumed " << i << " time(s)\n"; 51 52 }
Note: See TracChangeset
for help on using the changeset viewer.