Changeset 623c16a for src/tests


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

use forall distribution for buffer

Location:
src/tests/concurrent/examples
Files:
2 edited

Legend:

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

    r6d539f83 r623c16a  
    88// Created On       : Wed Apr 18 22:52:12 2018
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Fri Apr 20 22:25:14 2018
    11 // Update Count     : 6
     10// Last Modified On : Wed May  2 16:12:58 2018
     11// Update Count     : 7
    1212//
    1313
     
    2222enum { BufferSize = 50 };
    2323
    24 forall( otype T )
    25 monitor Buffer {
    26         int front, back, count;
    27         T elements[BufferSize];
    28 };
     24forall( otype T ) {
     25        monitor Buffer {
     26                int front, back, count;
     27                T elements[BufferSize];
     28        }; // Buffer
    2929
    30 forall( otype T )
    31 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; }
     30        void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; }
    3231
    33 forall( otype T )
    34 int query( Buffer(T) & buffer ) { return buffer.count; }
     32        int query( Buffer(T) & buffer ) { return buffer.count; } // read-only, no mutual exclusion
    3533
    36 forall( otype T )                                                                               // forward
    37 T remove( Buffer(T) & mutex buffer );
     34        T remove( Buffer(T) & mutex buffer );                           // forward
    3835
    39 forall( otype T )
    40 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) {
    41         if ( count == BufferSize ) waitfor( remove, buffer );
    42         elements[back] = elem;
    43         back = ( back + 1 ) % BufferSize;
    44         count += 1;
    45 }
     36        void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) {
     37                if ( count == BufferSize ) waitfor( remove, buffer );
     38                elements[back] = elem;
     39                back = ( back + 1 ) % BufferSize;
     40                count += 1;
     41        } // insert
    4642
    47 forall( otype T )
    48 T remove( Buffer(T) & mutex buffer ) with( buffer ) {
    49         if ( count == 0 ) waitfor( insert, buffer );
    50         T elem = elements[front];
    51         front = ( front + 1 ) % BufferSize;
    52         count -= 1;
    53         return elem;
     43        T remove( Buffer(T) & mutex buffer ) with( buffer ) {
     44                if ( count == 0 ) waitfor( insert, buffer );
     45                T elem = elements[front];
     46                front = ( front + 1 ) % BufferSize;
     47                count -= 1;
     48                return elem;
     49        } // remove
    5450}
    5551
  • 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.