Ignore:
Timestamp:
Mar 20, 2019, 3:42:24 PM (4 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
arm-eh, 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
Message:

Clean existing coroutines using std::experimental::suspend_never and fixed Format coroutines to use RAII

File:
1 edited

Legend:

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

    r13b1b1d r571bf75  
    1 
    2 #include "base.hpp"
     1#include <iostream>
     2#include <experimental/coroutine>
    33
    44struct fmt_cor {
    55        struct promise_type {
    66                char _value;
    7                 struct locals {
    8                         int g, b;
    9                 } * _l;
    107
    118                fmt_cor get_return_object() {
     
    1310                }
    1411
    15                 auto initial_suspend() { return suspend_never(); }
    16                 auto final_suspend()   { return suspend_always(); }
     12                auto initial_suspend() { return std::experimental::suspend_never(); }
     13                auto final_suspend()   { return std::experimental::suspend_always(); }
    1714
    1815                void return_void() {}
    1916                void unhandled_exception() {}
    20 
    21                 auto yield_value(locals & l) {
    22                         _l = &l;
    23                         return suspend_never();
    24                 }
    2517        };
    2618
     
    5042                if(_coroutine) {
    5143                        _coroutine.destroy();
    52                         if (_coroutine.promise()._l->g != 0 | _coroutine.promise()._l->b != 0) {
    53                                 std::cout << "\n";
    54                         }
     44
    5545                }
    5646        }
     
    7969
    8070fmt_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;
    8380        for(;;) {
    8481                for(l.g = 0; l.g < 5; l.g++) {
Note: See TracChangeset for help on using the changeset viewer.