Changeset b067d9b for tests/concurrent


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

Location:
tests/concurrent
Files:
6 added
41 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: //
  • 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: //
  • tests/concurrent/examples/datingService.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:56:20 2017
    911// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Sun May 27 09:05:18 2018
    11 // Update Count     : 26
     12// Last Modified On : Fri Jun 21 11:32:34 2019
     13// Update Count     : 38
    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
     
    3335                signal_block( Boys[ccode] );                                    // restart boy to set phone number
    3436        } // if
     37        sout | "Girl:" | PhoneNo | "is dating Boy at" | BoyPhoneNo | "with ccode" | ccode;
    3538        return BoyPhoneNo;
    3639} // DatingService girl
     
    4447                signal_block( Girls[ccode] );                                   // restart girl to set phone number
    4548        } // if
     49        sout | " Boy:" | PhoneNo | "is dating Girl" | GirlPhoneNo | "with ccode" | ccode;
    4650        return GirlPhoneNo;
    4751} // DatingService boy
     
    5862        yield( random( 100 ) );                                                         // don't all start at the same time
    5963        unsigned int partner = girl( TheExchange, id, ccode );
    60         sout | "Girl:" | id | "is dating Boy at" | partner | "with ccode" | ccode | endl;
    6164        girlck[id] = partner;
    6265} // Girl main
     
    6972
    7073thread Boy {
    71         DatingService &TheExchange;
     74        DatingService & TheExchange;
    7275        unsigned int id, ccode;
    7376}; // Boy
     
    7679        yield( random( 100 ) );                                                         // don't all start at the same time
    7780        unsigned int partner = boy( TheExchange, id, ccode );
    78         sout | " Boy:" | id | "is dating Girl" | partner | "with ccode" | ccode | endl;
    7981        boyck[id] = partner;
    8082} // Boy main
     
    9395        srandom( /*getpid()*/ 103 );
    9496
    95         for ( unsigned int i = 0; i < CompCodes; i += 1 ) {
    96                 girls[i] = new( &TheExchange, i, i );
     97        for ( i; (unsigned int)CompCodes ) {
     98                girls[i] = new( &TheExchange, i, i );                   // TheExchange constructor needs unsigned int
    9799                boys[i]  = new( &TheExchange, i, CompCodes - ( i + 1 ) );
    98100        } // for
    99101
    100         for ( unsigned int i = 0; i < CompCodes; i += 1 ) {
     102        for ( i; CompCodes ) {
    101103                delete( boys[i] );
    102104                delete( girls[i] );
    103105        } // for
    104106
    105         for ( unsigned int i = 0; i < CompCodes; i += 1 ) {
     107        for ( i; CompCodes ) {
    106108                if ( girlck[ boyck[i] ] != boyck[ girlck[i] ] ) abort();
    107109        } // for
     
    110112// Local Variables: //
    111113// tab-width: 4 //
    112 // compile-command: "cfa datingService.c" //
     114// compile-command: "cfa datingService.cfa" //
    113115// End: //
  • tests/concurrent/examples/matrixSum.cfa

    r7951100 rb067d9b  
    1 //                               -*- Mode: C -*-
    2 //
     1//
    32// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
    43//
    54// The contents of this file are covered under the licence agreement in the
    65// file "LICENCE" distributed with Cforall.
    7 // 
    8 // matrixSum.c --
    9 // 
     6//
     7// matrixSum.cfa --
     8//
    109// Author           : Peter A. Buhr
    1110// Created On       : Mon Oct  9 08:29:28 2017
    1211// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Fri May 25 09:34:27 2018
    14 // Update Count     : 10
    15 // 
     12// Last Modified On : Wed Feb 20 08:37:53 2019
     13// Update Count     : 16
     14//
    1615
    17 #include <fstream>
    18 #include <kernel>
    19 #include <thread>
     16#include <fstream.hfa>
     17#include <kernel.hfa>
     18#include <thread.hfa>
    2019
    2120thread Adder {
     
    3029void main( Adder & adder ) with( adder ) {                              // thread starts here
    3130        subtotal = 0;
    32         for ( int c = 0; c < cols; c += 1 ) {
     31        for ( c; cols ) {
    3332                subtotal += row[c];
    3433        } // for
     
    3635
    3736int main() {
    38         const int rows = 10, cols = 1000;
     37        /* const */ int rows = 10, cols = 1000;
    3938        int matrix[rows][cols], subtotals[rows], total = 0;
    4039        processor p;                                                                            // add kernel thread
    4140
    42         for ( int r = 0; r < rows; r += 1 ) {
    43                 for ( int c = 0; c < cols; c += 1 ) {
     41        for ( r; rows ) {
     42                for ( c; cols ) {
    4443                        matrix[r][c] = 1;
    4544                } // for
    4645        } // for
    4746        Adder * adders[rows];
    48         for ( int r = 0; r < rows; r += 1 ) {                           // start threads to sum rows
     47        for ( r; rows ) {                                                                       // start threads to sum rows
    4948                adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };
    5049//              adders[r] = new( matrix[r], cols, &subtotals[r] );
    5150        } // for
    52         for ( int r = 0; r < rows; r += 1 ) {                           // wait for threads to finish
     51        for ( r; rows ) {                                                                       // wait for threads to finish
    5352                delete( adders[r] );
    5453                total += subtotals[r];                                                  // total subtotals
    5554        } // for
    56         sout | total | endl;
     55        sout | total;
    5756}
    5857
    5958// Local Variables: //
    6059// tab-width: 4 //
    61 // compile-command: "cfa matrixSum.c" //
     60// compile-command: "cfa matrixSum.cfa" //
    6261// End: //
  • tests/concurrent/examples/quickSort.cfa

    r7951100 rb067d9b  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
    13//
    24// The contents of this file are covered under the licence agreement in the
     
    911// Created On       : Wed Dec  6 12:15:52 2017
    1012// Last Modified By : Peter A. Buhr
    11 // Last Modified On : Tue Jan 30 15:58:58 2018
    12 // Update Count     : 162
     13// Last Modified On : Thu Oct 10 13:58:18 2019
     14// Update Count     : 176
    1315//
    1416
    15 #include <fstream>
    16 #include <stdlib>
    17 #include <kernel>
    18 #include <thread>
     17#include <fstream.hfa>
     18#include <stdlib.hfa>
     19#include <kernel.hfa>
     20#include <thread.hfa>
    1921#include <string.h>                                                                             // strcmp
    2022
     
    6466                        if ( depth > 0 ) {
    6567                                depth -= 1;
    66                                 Quicksort rqs = { values, low, right, depth }; // concurrently sort upper half
    67                                 //Quicksort lqs( values, left, high, depth ); // concurrently sort lower half
    68                                 sort( values, left, high, depth );              // concurrently sort lower half
     68                                Quicksort lqs = { values, low, right, depth }; // concurrently sort lower half
     69                                Quicksort rqs = { values, left, high, depth }; // concurrently sort upper half
     70                                // Quicksort lqs = { values, low, right, depth }; // concurrently sort lower half
     71                                // sort( values, left, high, depth );           // concurrently sort upper half
    6972                        } else {
    7073                                sort( values, low, right, 0 );                  // sequentially sort lower half
     
    8891
    8992void usage( char * argv[] ) {
    90         sout | "Usage:" | argv[0] | "( -s unsorted-file [ sorted-file ] | -t size (>= 0) [ depth (>= 0) ] )" | endl;
     93        sout | "Usage:" | argv[0] | "( -s unsorted-file [ sorted-file ] | -t size (>= 0) [ depth (>= 0) ] )";
    9194        exit( EXIT_FAILURE );                                                           // TERMINATE!
    9295} // usage
     
    114117                                &sortedfile = new( (const char *)argv[2] ); // open the output file
    115118                                if ( fail( sortedfile ) ) {
    116                                         serr | "Error! Could not open sorted output file \"" | argv[2] | "\"" | endl;
     119                                        serr | "Error! Could not open sorted output file \"" | argv[2] | "\"";
    117120                                        usage( argv );
    118121                                } // if
     
    121124                                &unsortedfile = new( (const char *)argv[1] ); // open the input file
    122125                                if ( fail( unsortedfile ) ) {
    123                                         serr | "Error! Could not open unsorted input file \"" | argv[1] | "\"" | endl;
     126                                        serr | "Error! Could not open unsorted input file \"" | argv[1] | "\"";
    124127                                        usage( argv );
    125128                                } // if
     
    127130                } // if
    128131        } // if
     132        sortedfile | nlOff;                                                                     // turn off auto newline
    129133
    130134        enum { ValuesPerLine = 22 };                                            // number of values printed per line
    131135
    132136        if ( &unsortedfile ) {                                                          // generate output ?
    133                 for ( ;; ) {
     137                for () {
    134138                        unsortedfile | size;                                            // read number of elements in the list
    135139                  if ( eof( unsortedfile ) ) break;
    136140                        int * values = alloc( size );                           // values to be sorted, too large to put on stack
    137                         for ( int counter = 0; counter < size; counter += 1 ) { // read unsorted numbers
     141                        for ( counter; size ) {                                         // read unsorted numbers
    138142                                unsortedfile | values[counter];
    139                                 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | "  ";
     143                                if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | "  ";
    140144                                sortedfile | values[counter];
    141145                                if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' ';
    142146                        } // for
    143                         sortedfile | endl;
     147                        sortedfile | nl;
    144148                        if ( size > 0 ) {                                                       // values to sort ?
    145149                                Quicksort QS = { values, size - 1, 0 }; // sort values
    146150                        } // wait until sort tasks terminate
    147                         for ( int counter = 0; counter < size; counter += 1 ) { // print sorted list
    148                                 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | "  ";
     151                        for ( counter; size ) {                                         // print sorted list
     152                                if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | "  ";
    149153                                sortedfile | values[counter];
    150154                                if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' ';
    151155                        } // for
    152                         sortedfile | endl | endl;
     156                        sortedfile | nl | nl;
    153157
    154158                        delete( values );
     
    159163                processor processors[ (1 << depth) - 1 ] __attribute__(( unused )); // create 2^depth-1 kernel threads
    160164
    161                 int * values = alloc( size );                           // values to be sorted, too large to put on stack
    162                 for ( int counter = 0; counter < size; counter += 1 ) { // generate unsorted numbers
     165                int * values = alloc( size );                                   // values to be sorted, too large to put on stack
     166                for ( counter; size ) {                                                 // generate unsorted numbers
    163167                        values[counter] = size - counter;                       // descending values
     168                } // for
     169                for ( int i = 0; i < 200; i +=1 ) {                             // random shuffle a few values
     170                        swap( values[rand() % size], values[rand() % size] );
    164171                } // for
    165172                {
     
    167174                } // wait until sort tasks terminate
    168175
    169                 // for ( int counter = 0; counter < size - 1; counter += 1 ) { // check sorting
     176                // for ( counter; size - 1 ) {                          // check sorting
    170177                //      if ( values[counter] > values[counter + 1] ) abort();
    171178                // } // for
     
    175182} // main
    176183
     184// for depth in 0 1 2 3 4 5 ; do echo "sort 500000000 values with ${depth} depth" ; time -f "%Uu %Ss %E %Mkb" a.out -t 500000000 ${depth} ; done
     185
    177186// Local Variables: //
    178187// tab-width: 4 //
    179 // compile-command: "cfa quickSort.c" //
     188// compile-command: "cfa quickSort.cfa" //
    180189// End: //
  • tests/concurrent/monitor.cfa

    r7951100 rb067d9b  
    1 #include <fstream>
    2 #include <kernel>
    3 #include <monitor>
    4 #include <thread>
     1#include <fstream.hfa>
     2#include <kernel.hfa>
     3#include <monitor.hfa>
     4#include <thread.hfa>
    55
    66monitor global_t {
     
    4040                MyThread f[4];
    4141        }
    42         sout | global.value | endl;
     42        sout | global.value;
    4343}
  • tests/concurrent/multi-monitor.cfa

    r7951100 rb067d9b  
    1 #include <fstream>
    2 #include <kernel>
    3 #include <monitor>
    4 #include <thread>
     1#include <fstream.hfa>
     2#include <kernel.hfa>
     3#include <monitor.hfa>
     4#include <thread.hfa>
    55
    66static int global12, global23, global13;
     
    5252                }
    5353        }
    54         sout | global12 | global23 | global13 | endl;
     54        sout | global12 | global23 | global13;
    5555}
  • tests/concurrent/preempt.cfa

    r7951100 rb067d9b  
    1 #include <kernel>
    2 #include <thread>
    3 #include <time>
     1#include <kernel.hfa>
     2#include <thread.hfa>
     3#include <time.hfa>
     4
     5#include "long_tests.hfa"
    46
    57#ifndef PREEMPTION_RATE
     
    1113}
    1214
    13 #ifdef LONG_TEST
     15#ifdef TEST_LONG
    1416static const unsigned long N = 30_000ul;
    1517#else
     
    3032
    3133void main(worker_t & this) {
    32         while(counter < N) {
     34        while(TEST(counter < N)) {
    3335                __cfaabi_check_preemption();
    3436                if( (counter % 7) == this.value ) {
     
    4042                }
    4143                __cfaabi_check_preemption();
     44                KICK_WATCHDOG;
    4245        }
    4346}
  • tests/concurrent/signal/block.cfa

    r7951100 rb067d9b  
    77
    88
    9 #include <fstream>
    10 #include <kernel>
    11 #include <monitor>
    12 #include <stdlib>
    13 #include <thread>
    14 #include <time>
     9#include <fstream.hfa>
     10#include <kernel.hfa>
     11#include <monitor.hfa>
     12#include <stdlib.hfa>
     13#include <thread.hfa>
     14#include <time.hfa>
     15
     16#include "long_tests.hfa"
    1517
    1618#ifndef PREEMPTION_RATE
     
    2224}
    2325
    24 #ifdef LONG_TEST
     26#ifdef TEST_LONG
    2527static const unsigned long N = 150_000ul;
    2628#else
     
    5557
    5658        if(a.last_thread != a.last_signaller || b.last_thread != b.last_signaller ) {
    57                 sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread | endl;
     59                sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread;
    5860                abort();
    5961        }
     
    6668thread Waiter {};
    6769void main( Waiter & this ) {
    68         for( int i = 0; i < N; i++ ) {
     70        for( int i = 0; TEST(i < N); i++ ) {
    6971                wait_op( globalA, globalB, i );
     72                KICK_WATCHDOG;
    7073        }
    7174}
     
    8285
    8386                if( ! signal_block( cond ) ) {
    84                         sout | "ERROR expected to be able to signal" | endl;
     87                        sout | "ERROR expected to be able to signal";
    8588                        abort();
    8689                }
     
    8992
    9093                if(a.last_thread != next || b.last_thread != next) {
    91                         sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread | endl;
     94                        sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread;
    9295                        abort();
    9396                }
     
    127130                Signaller s[4];
    128131                Barger b[13];
    129                 sout | "Starting waiters" | endl;
     132                sout | "Starting waiters";
    130133                {
    131134                        Waiter w[3];
    132135                }
    133                 sout | "Waiters done" | endl;
     136                sout | "Waiters done";
    134137                done = true;
    135138        }
  • tests/concurrent/signal/disjoint.cfa

    r7951100 rb067d9b  
    1 #include <fstream>
    2 #include <kernel>
    3 #include <monitor>
    4 #include <thread>
    5 #include <time>
     1#include <fstream.hfa>
     2#include <kernel.hfa>
     3#include <monitor.hfa>
     4#include <thread.hfa>
     5#include <time.hfa>
     6
     7#include "long_tests.hfa"
    68
    79#ifndef PREEMPTION_RATE
     
    1315}
    1416
    15 #ifdef LONG_TEST
     17#ifdef TEST_LONG
    1618static const unsigned long N = 300_000ul;
    1719#else
     
    6466        wait( cond );
    6567        if( d.state != SIGNAL ) {
    66                 sout | "ERROR barging!" | endl;
     68                sout | "ERROR barging!";
    6769        }
    6870
    69         d.counter++;
     71        #if !defined(TEST_FOREVER)
     72                d.counter++;
     73                if( (d.counter % 1000) == 0 ) sout | d.counter;
     74        #endif
    7075
    71         if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
    72 
    73         return d.counter < N;
     76        return TEST(d.counter < N);
    7477}
    7578
     
    7780
    7881void main( Waiter & this ) {
    79         while( wait( mut, data ) ) { yield(); }
     82        while( wait( mut, data ) ) { KICK_WATCHDOG; yield(); }
    8083}
    8184
     
    9497
    9598        //This is technically a mutual exclusion violation but the mutex monitor protects us
    96         bool running = data.counter < N && data.counter > 0;
     99        bool running = TEST(data.counter < N) && data.counter > 0;
    97100        if( data.state != SIGNAL && running ) {
    98                 sout | "ERROR Eager signal" | data.state | endl;
     101                sout | "ERROR Eager signal" | data.state;
    99102        }
    100103}
     
    121124                        Waiter w[4];
    122125                }
    123                 sout | "All waiter done" | endl;
     126                sout | "All waiter done";
    124127                all_done = true;
    125128        }
  • tests/concurrent/signal/wait.cfa

    r7951100 rb067d9b  
    55
    66
    7 #include <fstream>
    8 #include <kernel>
    9 #include <monitor>
    10 #include <stdlib>
    11 #include <thread>
    12 #include <time>
     7#include <fstream.hfa>
     8#include <kernel.hfa>
     9#include <monitor.hfa>
     10#include <stdlib.hfa>
     11#include <thread.hfa>
     12#include <time.hfa>
     13
     14#define __kick_rate 12000ul
     15#include "long_tests.hfa"
    1316
    1417#ifndef PREEMPTION_RATE
     
    2023}
    2124
    22 #ifdef LONG_TEST
     25#ifdef TEST_LONG
    2326static const unsigned long N = 375_000ul;
    2427#else
     
    8083                                break;
    8184                        default:
    82                                 sout | "Something went wrong" | endl;
     85                                sout | "Something went wrong";
    8386                                abort();
    8487                }
     
    9093// Waiter ABC
    9194void main( WaiterABC & this ) {
    92         for( int i = 0; i < N; i++ ) {
     95        for( int i = 0; TEST(i < N); i++ ) {
    9396                wait( condABC, globalA, globalB, globalC );
     97                KICK_WATCHDOG;
    9498        }
    9599
     
    100104// Waiter AB
    101105void main( WaiterAB & this ) {
    102         for( int i = 0; i < N; i++ ) {
     106        for( int i = 0; TEST(i < N); i++ ) {
    103107                wait( condAB , globalA, globalB );
     108                KICK_WATCHDOG;
    104109        }
    105110
     
    110115// Waiter AC
    111116void main( WaiterAC & this ) {
    112         for( int i = 0; i < N; i++ ) {
     117        for( int i = 0; TEST(i < N); i++ ) {
    113118                wait( condAC , globalA, globalC );
     119                KICK_WATCHDOG;
    114120        }
    115121
     
    120126// Waiter BC
    121127void main( WaiterBC & this ) {
    122         for( int i = 0; i < N; i++ ) {
     128        for( int i = 0; TEST(i < N); i++ ) {
    123129                wait( condBC , globalB, globalC );
     130                KICK_WATCHDOG;
    124131        }
    125132
     
    133140        waiter_left = 4;
    134141        processor p[2];
    135         sout | "Starting" | endl;
     142        sout | "Starting";
    136143        {
    137144                Signaler  e;
     
    143150                }
    144151        }
    145         sout | "Done" | endl;
     152        sout | "Done";
    146153}
  • tests/concurrent/thread.cfa

    r7951100 rb067d9b  
    1 #include <fstream>
    2 #include <kernel>
    3 #include <stdlib>
    4 #include <thread>
     1#include <fstream.hfa>
     2#include <kernel.hfa>
     3#include <stdlib.hfa>
     4#include <thread.hfa>
    55
    66thread First  { semaphore* lock; };
     
    1212void main(First& this) {
    1313        for(int i = 0; i < 10; i++) {
    14                 sout | "First : Suspend No." | i + 1 | endl;
     14                sout | "First : Suspend No." | i + 1;
    1515                yield();
    1616        }
     
    2121        P(*this.lock);
    2222        for(int i = 0; i < 10; i++) {
    23                 sout | "Second : Suspend No." | i + 1 | endl;
     23                sout | "Second : Suspend No." | i + 1;
    2424                yield();
    2525        }
     
    2929int main(int argc, char* argv[]) {
    3030        semaphore lock = { 0 };
    31         sout | "User main begin" | endl;
     31        sout | "User main begin";
    3232        {
    3333                processor p;
     
    3737                }
    3838        }
    39         sout | "User main end" | endl;
     39        sout | "User main end";
    4040}
  • tests/concurrent/waitfor/barge.cfa

    r7951100 rb067d9b  
    66//---------------------------------------------------------
    77
    8 #include <fstream>
    9 #include <kernel>
    10 #include <monitor>
    11 #include <stdlib>
    12 #include <thread>
     8#include <fstream.hfa>
     9#include <kernel.hfa>
     10#include <monitor.hfa>
     11#include <stdlib.hfa>
     12#include <thread.hfa>
    1313
    1414#include <stdbool.h>
     
    4848        yield(random( 10 ));
    4949        if( this.state != WAITFOR && !this.done && this.started ) {
    50                 serr | "Barging before caller detected" | endl;
     50                serr | "Barging before caller detected";
    5151        }
    5252
     
    6666                this.state = WAITFOR;
    6767                waitfor(do_call, this) {
    68                         sout | i | endl;
     68                        sout | i;
    6969                }
    7070
    7171                if( this.state != CALL ) {
    72                         serr | "Barging after caller detected" | endl;
     72                        serr | "Barging after caller detected";
    7373                }
    7474        }
     
    8383
    8484int main() {
    85         sout | "Starting" | endl;
     85        sout | "Starting";
    8686        {
    8787                barger_t bargers[17];
     
    8989                waiter_t waiters;
    9090        }
    91         sout | "Stopping" | endl;
     91        sout | "Stopping";
    9292}
  • tests/concurrent/waitfor/dtor.cfa

    r7951100 rb067d9b  
    44//---------------------------------------------------------
    55
    6 #include <fstream>
    7 #include <kernel>
    8 #include <monitor>
    9 #include <stdlib>
    10 #include <thread>
     6#include <fstream.hfa>
     7#include <kernel.hfa>
     8#include <monitor.hfa>
     9#include <stdlib.hfa>
     10#include <thread.hfa>
    1111
    1212#include <stdbool.h>
     
    2929        switch(state) {
    3030                case CTOR  : break;
    31                 case MAIN  : if( this.state != CTOR  ) { serr | "ERROR Expected state to be CTOR"  | endl; abort(); } this.state = state; break;
    32                 case AFTER : if( this.state != MAIN  ) { serr | "ERROR Expected state to be MAIN"  | endl; abort(); } this.state = state; break;
    33                 case END   : if( this.state != AFTER ) { serr | "ERROR Expected state to be AFTER" | endl; abort(); } this.state = state; break;
    34                 case DTOR  : if( this.state != END   ) { serr | "ERROR Expected state to be END"   | endl; abort(); } this.state = state; break;
     31                case MAIN  : if( this.state != CTOR  ) { serr | "ERROR Expected state to be CTOR" ; abort(); } this.state = state; break;
     32                case AFTER : if( this.state != MAIN  ) { serr | "ERROR Expected state to be MAIN" ; abort(); } this.state = state; break;
     33                case END   : if( this.state != AFTER ) { serr | "ERROR Expected state to be AFTER"; abort(); } this.state = state; break;
     34                case DTOR  : if( this.state != END   ) { serr | "ERROR Expected state to be END"  ; abort(); } this.state = state; break;
    3535        }
    3636}
     
    5454
    5555int main() {
    56         sout | "Starting" | endl;
     56        sout | "Starting";
    5757        processor p;
    5858        for( int i = 0; i < N; i++ ){
     
    6060                yield( random( 100 ) );
    6161        }
    62         sout | "Stopping" | endl;
     62        sout | "Stopping";
    6363}
  • tests/concurrent/waitfor/else.cfa

    r7951100 rb067d9b  
    1 #include <fstream>
    2 #include <monitor>
     1#include <fstream.hfa>
     2#include <monitor.hfa>
    33
    44#include <stdbool.h>
     
    1212void test( M & mutex m ) {
    1313        int i = 0;
    14         sout | "Starting" | endl;
     14        sout | "Starting";
    1515
    1616        when( false ) waitfor( notcalled, m );
    1717
    18         sout | "Step" | i++ | endl;
     18        sout | "Step" | i++;
    1919
    2020        waitfor( notcalled, m ); or else {
    21                 sout | "else called" | endl;
     21                sout | "else called";
    2222        }
    2323
    24         sout | "Step" | i++ | endl;
     24        sout | "Step" | i++;
    2525
    2626        when( true ) waitfor( notcalled, m ); or when( true ) else {
    27                 sout | "else called" | endl;
     27                sout | "else called";
    2828        }
    2929
    30         sout | "Step" | i++ | endl;
     30        sout | "Step" | i++;
    3131
    3232        when( false ) waitfor( notcalled, m ); or when( true ) else {
    33                 sout | "else called" | endl;
     33                sout | "else called";
    3434        }
    3535
    36         sout | "Step" | i++ | endl;
     36        sout | "Step" | i++;
    3737
    3838        when( false ) waitfor( notcalled, m ); or when( false ) else {
    39                 sout | "else called" | endl;
     39                sout | "else called";
    4040        }
    4141
    42         sout | "Done" | endl;
     42        sout | "Done";
    4343}
    4444
  • tests/concurrent/waitfor/parse.cfa

    r7951100 rb067d9b  
    88//----------------------------------------------------------------------------------------
    99
    10 #include <monitor>
     10#include <monitor.hfa>
    1111
    1212monitor M {};
  • tests/concurrent/waitfor/parse2.cfa

    r7951100 rb067d9b  
    1010// Created On       : Wed Aug 30 17:53:29 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 30 17:55:17 2017
    13 // Update Count     : 2
     12// Last Modified On : Fri Mar 22 13:42:11 2019
     13// Update Count     : 3
    1414//
    1515
     
    246246// Local Variables: //
    247247// tab-width: 4 //
    248 // compile-command: "cfa waitfor.c" //
     248// compile-command: "cfa waitfor.cfa" //
    249249// End: //
  • tests/concurrent/waitfor/recurse.cfa

    r7951100 rb067d9b  
    44//-----------------------------------------------------------------
    55
    6 #include <fstream>
    7 #include <kernel>
    8 #include <monitor>
    9 #include <stdlib>
    10 #include <thread>
     6#include <fstream.hfa>
     7#include <kernel.hfa>
     8#include <monitor.hfa>
     9#include <stdlib.hfa>
     10#include <thread.hfa>
    1111
    1212#include <stdbool.h>
     
    9595        rand_yield();
    9696
    97         sout | "1st" | endl;
     97        sout | "1st" | nl;
    9898
    9999        return this.counter < N ? (state_t)this.actions[idx] : (state_t)STOP;
     
    123123                        case THIRD  : while( !global.ready ) { yield(); } this.state = call3( global, this.idx ); break;
    124124                        case LAST   : while( !global.ready ) { yield(); } this.state = call4( global, this.idx ); break;
    125                         case STOP   : serr | "This should not happen" | endl;
     125                        case STOP   : serr | "This should not happen" | nl;
    126126                }
    127127        }
     
    132132int main() {
    133133        srandom( time(NULL) );
    134         sout | "Starting" | endl;
     134        sout | nlOff;                                   // turn off auto newline
     135        sout | "Starting" | nl;
    135136        {
    136137                waiter_t waiters[4] = {
     
    142143                the_threads = waiters;
    143144        }
    144         sout | "Stopping" | endl;
     145        sout | "Stopping" | nl;
    145146}
  • tests/concurrent/waitfor/simple.cfa

    r7951100 rb067d9b  
    1 #include <fstream>
    2 #include <kernel>
    3 #include <monitor>
    4 #include <stdlib>
    5 #include <thread>
     1#include <fstream.hfa>
     2#include <kernel.hfa>
     3#include <monitor.hfa>
     4#include <stdlib.hfa>
     5#include <thread.hfa>
    66
    77#include <time.h>
     
    3131
    3232void do_wait( global_t * mutex a ) {
    33         sout | "Waiting to accept" | endl;
     33        sout | "Waiting to accept";
    3434        yield( random( 10 ) );
    3535
    36         sout | "Accepting" | endl;
     36        sout | "Accepting";
    3737
    3838        __acceptable_t acceptable;
     
    4343        __waitfor_internal( 1, &acceptable );
    4444
    45         sout | "Accepted" | endl;
     45        sout | "Accepted";
    4646        yield( random( 10 ) );
    4747}
     
    5050        for( int i = 0; i < N; i++ ) {
    5151                do_wait( &globalA );
    52                 sout | i | endl;
     52                sout | i;
    5353        }
    5454
     
    7676        srandom( time( NULL ) );
    7777        printf("%p\n", &globalA);
    78         sout | "Starting" | endl;
     78        sout | "Starting";
    7979        {
    8080                Acceptor r;
     
    8282
    8383        }
    84         sout | "Done" | endl;
     84        sout | "Done";
    8585}
  • tests/concurrent/waitfor/statment.cfa

    r7951100 rb067d9b  
    1 #include <fstream>
    2 #include <kernel>
    3 #include <monitor>
    4 #include <thread>
     1#include <fstream.hfa>
     2#include <kernel.hfa>
     3#include <monitor.hfa>
     4#include <thread.hfa>
    55
    66#include <stdbool.h>
     
    8484                case 7: return call7( m );
    8585                default :
    86                         serr | "Incorrect index" | index | endl;
     86                        serr | "Incorrect index" | index;
    8787                        abort();
    8888        }
     
    102102        while( !done ) {
    103103                   waitfor( get_index, this );
    104                 or waitfor( call1, this ) { sout | "Statement" | endl; if( this.last_val != 1 ) { serr | "Incorrect index: expected" | 1 | "got" | this.last_val | endl; } }
    105                 or waitfor( call2, this ) { sout | "Statement" | endl; if( this.last_val != 2 ) { serr | "Incorrect index: expected" | 2 | "got" | this.last_val | endl; } }
    106                 or waitfor( call3, this ) { sout | "Statement" | endl; if( this.last_val != 3 ) { serr | "Incorrect index: expected" | 3 | "got" | this.last_val | endl; } }
    107                 or waitfor( call4, this ) { sout | "Statement" | endl; if( this.last_val != 4 ) { serr | "Incorrect index: expected" | 4 | "got" | this.last_val | endl; } }
    108                 or waitfor( call5, this ) { sout | "Statement" | endl; if( this.last_val != 5 ) { serr | "Incorrect index: expected" | 5 | "got" | this.last_val | endl; } }
    109                 or waitfor( call6, this ) { sout | "Statement" | endl; if( this.last_val != 6 ) { serr | "Incorrect index: expected" | 6 | "got" | this.last_val | endl; } }
    110                 or waitfor( call7, this ) { sout | "Statement" | endl; if( this.last_val != 7 ) { serr | "Incorrect index: expected" | 7 | "got" | this.last_val | endl; } }
     104                or waitfor( call1, this ) { sout | "Statement"; if( this.last_val != 1 ) { serr | "Incorrect index: expected" | 1 | "got" | this.last_val; } }
     105                or waitfor( call2, this ) { sout | "Statement"; if( this.last_val != 2 ) { serr | "Incorrect index: expected" | 2 | "got" | this.last_val; } }
     106                or waitfor( call3, this ) { sout | "Statement"; if( this.last_val != 3 ) { serr | "Incorrect index: expected" | 3 | "got" | this.last_val; } }
     107                or waitfor( call4, this ) { sout | "Statement"; if( this.last_val != 4 ) { serr | "Incorrect index: expected" | 4 | "got" | this.last_val; } }
     108                or waitfor( call5, this ) { sout | "Statement"; if( this.last_val != 5 ) { serr | "Incorrect index: expected" | 5 | "got" | this.last_val; } }
     109                or waitfor( call6, this ) { sout | "Statement"; if( this.last_val != 6 ) { serr | "Incorrect index: expected" | 6 | "got" | this.last_val; } }
     110                or waitfor( call7, this ) { sout | "Statement"; if( this.last_val != 7 ) { serr | "Incorrect index: expected" | 7 | "got" | this.last_val; } }
    111111
    112112                done = true;
     
    128128int main() {
    129129        processor p[2];
    130         sout | "Starting" | endl;
     130        sout | "Starting";
    131131        {
    132132                caller c[7];
    133133                waiter w;
    134134        }
    135         sout | "Stopping" | endl;
     135        sout | "Stopping";
    136136}
  • tests/concurrent/waitfor/when.cfa

    r7951100 rb067d9b  
    44//-----------------------------------------------------------------
    55
    6 #include <fstream>
    7 #include <kernel>
    8 #include <monitor>
    9 #include <stdlib>
    10 #include <thread>
     6#include <fstream.hfa>
     7#include <kernel.hfa>
     8#include <monitor.hfa>
     9#include <stdlib.hfa>
     10#include <thread.hfa>
    1111
    1212#include <stdbool.h>
     
    5858void arbiter( global_t & mutex this ) {
    5959        for( int i = 0; i < N; i++ ) {
    60                    when( this.last_call == 6 ) waitfor( call1, this ) { if( this.last_call != 1) { serr | "Expected last_call to be 1 got" | this.last_call | endl; } }
    61                 or when( this.last_call == 1 ) waitfor( call2, this ) { if( this.last_call != 2) { serr | "Expected last_call to be 2 got" | this.last_call | endl; } }
    62                 or when( this.last_call == 2 ) waitfor( call3, this ) { if( this.last_call != 3) { serr | "Expected last_call to be 3 got" | this.last_call | endl; } }
    63                 or when( this.last_call == 3 ) waitfor( call4, this ) { if( this.last_call != 4) { serr | "Expected last_call to be 4 got" | this.last_call | endl; } }
    64                 or when( this.last_call == 4 ) waitfor( call5, this ) { if( this.last_call != 5) { serr | "Expected last_call to be 5 got" | this.last_call | endl; } }
    65                 or when( this.last_call == 5 ) waitfor( call6, this ) { if( this.last_call != 6) { serr | "Expected last_call to be 6 got" | this.last_call | endl; } }
     60                   when( this.last_call == 6 ) waitfor( call1, this ) { if( this.last_call != 1) { serr | "Expected last_call to be 1 got" | this.last_call; } }
     61                or when( this.last_call == 1 ) waitfor( call2, this ) { if( this.last_call != 2) { serr | "Expected last_call to be 2 got" | this.last_call; } }
     62                or when( this.last_call == 2 ) waitfor( call3, this ) { if( this.last_call != 3) { serr | "Expected last_call to be 3 got" | this.last_call; } }
     63                or when( this.last_call == 3 ) waitfor( call4, this ) { if( this.last_call != 4) { serr | "Expected last_call to be 4 got" | this.last_call; } }
     64                or when( this.last_call == 4 ) waitfor( call5, this ) { if( this.last_call != 5) { serr | "Expected last_call to be 5 got" | this.last_call; } }
     65                or when( this.last_call == 5 ) waitfor( call6, this ) { if( this.last_call != 6) { serr | "Expected last_call to be 6 got" | this.last_call; } }
    6666
    67                 sout | this.last_call | endl;
     67                sout | this.last_call;
    6868        }
    6969
     
    7878int main() {
    7979        srandom( time(NULL) );
    80         sout | "Starting" | endl;
     80        sout | "Starting";
    8181        {
    8282                arbiter_t arbiter;
     
    8484
    8585        }
    86         sout | "Stopping" | endl;
     86        sout | "Stopping";
    8787}
Note: See TracChangeset for help on using the changeset viewer.