Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 moved

Legend:

Unmodified
Added
Removed
  • tests/concurrent/examples/boundedBufferEXT.cfa

    r7951100 rb067d9b  
    11//
     2// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
     3//
    24// The contents of this file are covered under the licence agreement in the
    35// file "LICENCE" distributed with Cforall.
     
    810// Created On       : Wed Apr 18 22:52:12 2018
    911// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Wed May  2 16:12:58 2018
    11 // Update Count     : 7
     12// Last Modified On : Fri Jun 21 08:19:20 2019
     13// Update Count     : 14
    1214//
    1315
    14 #include <stdlib>                                                                               // random
    15 #include <fstream>
    16 #include <kernel>
    17 #include <thread>
     16#include <stdlib.hfa>                                                                   // random
     17#include <fstream.hfa>
     18#include <kernel.hfa>
     19#include <thread.hfa>
    1820#include <unistd.h>                                                                             // getpid
    1921
     
    5052}
    5153
    52 const int Sentinel = -1;
     54enum { Sentinel = -1 };
    5355
    5456thread Producer {
     
    5759};
    5860void main( Producer & prod ) with( prod ) {
    59         for ( int i = 1; i <= N; i += 1 ) {
     61        for ( i; 1 ~= N ) {
    6062                yield( random( 5 ) );
    6163                insert( buffer, 1 );
     
    7375void main( Consumer & cons ) with( cons ) {
    7476        sum = 0;
    75         for ( ;; ) {
     77        for () {
    7678                yield( random( 5 ) );
    7779                int item = remove( buffer );
     
    9799        srandom( 1003 );
    98100
    99         for ( i = 0; i < Cons; i += 1 ) {                                       // create consumers
     101        for ( i; Cons ) {                                                                       // create consumers
    100102                cons[i] = new( &buffer, sums[i] );
    101103        } // for
    102         for ( i = 0; i < Prods; i += 1 ) {                                      // create producers
     104        for ( i; Prods ) {                                                                      // create producers
    103105                prods[i] = new( &buffer, 100000 );
    104106        } // for
    105107
    106         for ( i = 0; i < Prods; i += 1 ) {                                      // wait for producers to finish
     108        for ( i; Prods ) {                                                                      // wait for producers to finish
    107109                delete( prods[i] );
    108110        } // for
    109         for ( i = 0; i < Cons; i += 1 ) {                                       // generate sentinal values to stop consumers
     111        for ( i; Cons ) {                                                                       // generate sentinal values to stop consumers
    110112                insert( buffer, Sentinel );
    111113        } // for
    112114        int sum = 0;
    113         for ( i = 0; i < Cons; i += 1 ) {                                       // wait for consumers to finish
     115        for ( i; Cons ) {                                                                       // wait for consumers to finish
    114116                delete( cons[i] );
    115117                sum += sums[i];
    116118        } // for
    117         sout | "total:" | sum | endl;
     119        sout | "total:" | sum;
    118120}
    119121
    120122// Local Variables: //
    121123// tab-width: 4 //
    122 // compile-command: "cfa boundedBufferEXT.c" //
     124// compile-command: "cfa boundedBufferEXT.cfa" //
    123125// End: //
Note: See TracChangeset for help on using the changeset viewer.