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/boundedBufferINT.cfa

    r7951100 rb067d9b  
    11//
     2// Cforall Version 1.0.0 Copyright (C) 2017 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       : Mon Oct 30 12:45:13 2017
    911// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Thu Apr 26 23:08:17 2018
    11 // Update Count     : 82
     12// Last Modified On : Fri Jun 21 08:20:46 2019
     13// Update Count     : 90
    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
     
    5153}
    5254
    53 const int Sentinel = -1;
     55enum { Sentinel = -1 };
    5456
    5557thread Producer {
     
    5860};
    5961void main( Producer & prod ) with( prod ) {
    60         for ( int i = 1; i <= N; i += 1 ) {
     62        for ( i; 1 ~= N ) {
    6163                yield( random( 5 ) );
    6264                insert( buffer, 1 );
     
    7476void main( Consumer & cons ) with( cons ) {
    7577        sum = 0;
    76         for ( ;; ) {
     78        for () {
    7779                yield( random( 5 ) );
    7880                int item = remove( buffer );
     
    98100        srandom( 1003 );
    99101
    100         for ( i = 0; i < Cons; i += 1 ) {                                       // create consumers
     102        for ( i; Cons ) {                                                                       // create consumers
    101103                cons[i] = new( &buffer, sums[i] );
    102104        } // for
    103         for ( i = 0; i < Prods; i += 1 ) {                                      // create producers
     105        for ( i; Prods ) {                                                                      // create producers
    104106                prods[i] = new( &buffer, 100000 );
    105107        } // for
    106108
    107         for ( i = 0; i < Prods; i += 1 ) {                                      // wait for producers to finish
     109        for ( i; Prods ) {                                                                      // wait for producers to finish
    108110                delete( prods[i] );
    109111        } // for
    110         for ( i = 0; i < Cons; i += 1 ) {                                       // generate sentinal values to stop consumers
     112        for ( i; Cons ) {                                                                       // generate sentinal values to stop consumers
    111113                insert( buffer, Sentinel );
    112114        } // for
    113115        int sum = 0;
    114         for ( i = 0; i < Cons; i += 1 ) {                                       // wait for consumers to finish
     116        for ( i; Cons ) {                                                                       // wait for consumers to finish
    115117                delete( cons[i] );
    116118                sum += sums[i];
    117119        } // for
    118         sout | "total:" | sum | endl;
     120        sout | "total:" | sum;
    119121}
    120122
    121123// Local Variables: //
    122124// tab-width: 4 //
    123 // compile-command: "cfa boundedBufferINT.c" //
     125// compile-command: "cfa boundedBufferINT.cfa" //
    124126// End: //
Note: See TracChangeset for help on using the changeset viewer.