Ignore:
Timestamp:
May 2, 2018, 4:18:37 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, with_gc
Children:
68e9ace
Parents:
6d539f83
Message:

use forall distribution for buffer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/concurrent/examples/boundedBufferINT.c

    r6d539f83 r623c16a  
    88// Created On       : Mon Oct 30 12:45:13 2017
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Fri Apr 20 22:18:18 2018
    11 // Update Count     : 78
     10// Last Modified On : Thu Apr 26 23:08:17 2018
     11// Update Count     : 82
    1212//
    1313
     
    2222enum { BufferSize = 50 };
    2323
    24 forall( otype T )
    25 monitor Buffer {
    26         condition full, empty;
    27         int front, back, count;
    28         T elements[BufferSize];
    29 };
     24forall( otype T ) {
     25        monitor Buffer {
     26                condition full, empty;
     27                int front, back, count;
     28                T elements[BufferSize];
     29        }; // Buffer
    3030
    31 forall( otype T )
    32 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; }
     31        void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; }
    3332
    34 forall( otype T )
    35 int query( Buffer(T) & buffer ) { return buffer.count; }
     33        int query( Buffer(T) & buffer ) { return buffer.count; } // read-only, no mutual exclusion
    3634
    37 forall( otype T )
    38 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) {
    39         if ( count == BufferSize ) wait( empty );
    40         elements[back] = elem;
    41         back = ( back + 1 ) % BufferSize;
    42         count += 1;
    43         signal( full );
    44 }
     35        void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) {
     36                if ( count == BufferSize ) wait( empty );
     37                elements[back] = elem;
     38                back = ( back + 1 ) % BufferSize;
     39                count += 1;
     40                signal( full );
     41        } // insert
    4542
    46 forall( otype T )
    47 T remove( Buffer(T) & mutex buffer ) with( buffer ) {
    48         if ( count == 0 ) wait( full );
    49         T elem = elements[front];
    50         front = ( front + 1 ) % BufferSize;
    51         count -= 1;
    52         signal( empty );
    53         return elem;
     43        T remove( Buffer(T) & mutex buffer ) with( buffer ) {
     44                if ( count == 0 ) wait( full );
     45                T elem = elements[front];
     46                front = ( front + 1 ) % BufferSize;
     47                count -= 1;
     48                signal( empty );
     49                return elem;
     50        } // remove
    5451}
    5552
Note: See TracChangeset for help on using the changeset viewer.