Changeset a1ecdd1


Ignore:
Timestamp:
Dec 13, 2017, 9:11:25 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, resolv-new, with_gc
Children:
1edf37f, 59073fd
Parents:
edb6f79
Message:

generic bounded buffer, not working

File:
1 edited

Legend:

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

    redb6f79 ra1ecdd1  
    88// Created On       : Mon Oct 30 12:45:13 2017
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Tue Dec  5 23:01:51 2017
    11 // Update Count     : 10
     10// Last Modified On : Wed Dec 13 21:01:49 2017
     11// Update Count     : 27
    1212//
    1313
     
    1818#include <unistd.h>                                                                             // getpid
    1919
     20forall( otype T )
    2021monitor Buffer {
    2122        condition full, empty;
    2223        int front, back, count;
    23         int elements[20];
     24        T elements[20];
    2425};
    2526
    26 void ?{}( Buffer & buffer ) {
     27forall( otype T )
     28void ?{}( Buffer(T) & buffer ) {
    2729        buffer.front = buffer.back = buffer.count = 0;
    2830}
    2931
    30 int query( Buffer & buffer ) { return buffer.count; }
     32forall( otype T )
     33int query( Buffer(T) & buffer ) { return buffer.count; }
    3134
    32 void insert( Buffer & mutex buffer, int elem ) with( buffer ) {
     35forall( otype T )
     36void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) {
    3337        if ( count == 20 ) wait( empty );
    3438        elements[back] = elem;
     
    3741        signal( full );
    3842}
    39 int remove( Buffer & mutex buffer ) with( buffer ) {
     43
     44forall( otype T )
     45T remove( Buffer(T) & mutex buffer ) with( buffer ) {
    4046        if ( count == 0 ) wait( full );
    41         int elem = elements[front];
     47        T elem = elements[front];
    4248        front = ( front + 1 ) % 20;
    4349        count -= 1;
     
    4753
    4854thread Producer {
    49         Buffer & buffer;
     55        Buffer(int) & buffer;
    5056        unsigned int N;
    5157};
     
    5763        insert( prod.buffer, -1 );
    5864}
    59 void ?{}( Producer & prod, Buffer * buffer, unsigned int N ) {
     65void ?{}( Producer & prod, Buffer(int) * buffer, unsigned int N ) {
    6066        &prod.buffer = buffer;
    6167        prod.N = N;
    62                 }
     68}
    6369
    6470thread Consumer {
    65         Buffer & buffer;
     71        Buffer(int) & buffer;
    6672        int & sum;                                              // summation of producer values
    6773};
     
    7581        } // for
    7682}
    77 void ?{}( Consumer & cons, Buffer * buffer, int * sum ) {
     83void ?{}( Consumer & cons, Buffer(int) * buffer, int * sum ) {
    7884        &cons.buffer = buffer;
    7985        &cons.sum = sum;
     
    8187
    8288int main() {
    83         Buffer buffer;
     89        Buffer(int) buffer;
    8490        enum { Prods = 5, Cons = 5 };
    8591        Producer * prods[Prods];
Note: See TracChangeset for help on using the changeset viewer.