Changeset 13b1b1d


Ignore:
Timestamp:
Mar 20, 2019, 2:16:10 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:
571bf75
Parents:
aa22c60
Message:

C++ Format coroutine now "properly" destroys itself

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/concurrency/examples/Format.cpp

    raa22c60 r13b1b1d  
    55        struct promise_type {
    66                char _value;
    7                 int g, b;
     7                struct locals {
     8                        int g, b;
     9                } * _l;
    810
    911                fmt_cor get_return_object() {
     
    1618                void return_void() {}
    1719                void unhandled_exception() {}
     20
     21                auto yield_value(locals & l) {
     22                        _l = &l;
     23                        return suspend_never();
     24                }
    1825        };
    1926
     
    4148
    4249        ~fmt_cor() {
    43                 if(_coroutine) { _coroutine.destroy(); }
     50                if(_coroutine) {
     51                        _coroutine.destroy();
     52                        if (_coroutine.promise()._l->g != 0 | _coroutine.promise()._l->b != 0) {
     53                                std::cout << "\n";
     54                        }
     55                }
    4456        }
    4557
     
    6779
    6880fmt_cor Fmt() {
    69         int g; // = co_await fmt_cor::g();
    70         int b; // = co_await fmt_cor::b();
     81        fmt_cor::promise_type::locals l;
     82        co_yield l;
    7183        for(;;) {
    72                 for(g = 0; g < 5; g++) {
    73                         for(b = 0; b < 4; b++) {
     84                for(l.g = 0; l.g < 5; l.g++) {
     85                        for(l.b = 0; l.b < 4; l.b++) {
    7486                                std::cout << co_await fmt_cor::get();
    7587                        }
Note: See TracChangeset for help on using the changeset viewer.