Ignore:
Timestamp:
Jan 10, 2019, 3:50:34 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
d97c3a4
Parents:
aeb8f70 (diff), 08222c7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Aaron Moss <a3moss@…> (01/10/19 14:46:09)
git-committer:
Aaron Moss <a3moss@…> (01/10/19 15:50:34)
Message:

Merge remote-tracking branch 'plg/master' into deferred_resn

File:
1 moved

Legend:

Unmodified
Added
Removed
  • tests/coroutine/prodcons.cfa

    raeb8f70 re99e43f  
    1010// Created On       : Mon Sep 18 12:23:39 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 18 12:55:10 2018
    13 // Update Count     : 51
     12// Last Modified On : Wed Dec 12 23:04:49 2018
     13// Update Count     : 53
    1414//
    1515
     
    2424
    2525coroutine Prod {
    26         Cons * c;
     26        Cons & c;
    2727        int N, money, receipt;
    2828};
     
    3030        // 1st resume starts here
    3131        for ( i; N ) {                                                                          // N pairs of values
    32                 int p1 = random( 100 );
    33                 int p2 = random( 100 );
    34                 sout | p1 | " " | p2 | endl;
    35                 int status = delivery( *c, p1, p2 );
    36                 sout | " $" | money | endl;
    37                 sout | status | endl;
     32                int p1 = random( 100 ), p2 = random( 100 );
     33                sout | p1 | " " | p2;
     34                int status = delivery( c, p1, p2 );
     35                sout | " $" | money | nl | status;
    3836                receipt += 1;
    3937        }
    40         stop( *c );
    41         sout | "prod stops" | endl;
     38        stop( c );
     39        sout | "prod stops";
    4240}
    4341int payment( Prod & prod, int money ) {
     
    4745}
    4846void start( Prod & prod, int N, Cons &c ) {
    49         prod.N = N;
    50         prod.c = &c;
    51         prod.receipt = 0;
     47        &prod.c = &c;
     48        prod.[N, receipt] = [N, 0];
    5249        resume( prod );                                                                         // activate main
    5350}
    5451
    5552coroutine Cons {
    56         Prod * p;
     53        Prod & p;
    5754        int p1, p2, status;
    5855        bool done;
    5956};
    6057void ?{}( Cons & cons, Prod & p ) {
    61         cons.p = &p;
    62         cons.status = 0;
    63         cons.done = false;
     58        &cons.p = &p;
     59        cons.[status, done ] = [0, false];
    6460}
    6561void ^?{}( Cons & cons ) {}
     
    6864        int money = 1, receipt;
    6965        for ( ; ! done; ) {
    70                 sout | p1 | " " | p2 | endl;
    71                 sout | " $" | money | endl;
     66                sout | p1 | " " | p2 | nl | " $" | money;
    7267                status += 1;
    73                 receipt = payment( *p, money );
    74                 sout | " #" | receipt | endl;
     68                receipt = payment( p, money );
     69                sout | " #" | receipt;
    7570                money += 1;
    7671        }
    77         sout | "cons stops" | endl;
     72        sout | "cons stops";
    7873}
    7974int delivery( Cons & cons, int p1, int p2 ) {
    80         cons.p1 = p1;
    81         cons.p2 = p2;
     75        cons.[p1, p2] = [p1, p2];
    8276        resume( cons );                                                                         // main 1st time, then
    8377        return cons.status;                                                                     // cons in payment
     
    9286        srandom( /* getpid() */ 103 );                                          // fixed seed for testing
    9387        start( prod, 5, cons );
    94         sout | "main stops" | endl;
     88        sout | "main stops";
    9589}
    9690
Note: See TracChangeset for help on using the changeset viewer.