Changeset 237df76 for tests


Ignore:
Timestamp:
Oct 6, 2021, 8:40:19 PM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
05c941a, 68fe946e
Parents:
8dcb832
Message:

convert from test programs I/O acquire to mutex statement

Location:
tests
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/semaphore.cfa

    r8dcb832 r237df76  
    22#include <locks.hfa>
    33#include <thread.hfa>
     4#include <mutex_stmt.hfa>
    45
    56enum { num_blockers = 17, num_unblockers = 13 };
     
    2829                thrash();
    2930                P(ben);
    30                 if(((thread&)this).seqable.next != 0p) sout | acquire |"Link not invalidated";
     31                if(((thread&)this).seqable.next != 0p) mutex(sout) sout | "Link not invalidated";
    3132                thrash();
    3233        }
  • tests/concurrent/sleep.cfa

    r8dcb832 r237df76  
    11#include <fstream.hfa>
    22#include <thread.hfa>
     3#include <mutex_stmt.hfa>
    34#include <time.hfa>
    45
     
    2930
    3031int main() {
    31         sout | acquire | "start";
     32        mutex( sout ) sout | "start";
    3233        {
    3334                slow_sleeper slow;
     
    3637                yield();
    3738        }
    38         sout | acquire | "done";
     39        mutex( sout ) sout | "done";
    3940}
    4041
  • tests/io/io-acquire.cfa

    r8dcb832 r237df76  
    1010// Created On       : Mon Mar  1 18:40:09 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 27 11:49:34 2021
    13 // Update Count     : 18
     12// Last Modified On : Wed Oct  6 18:04:58 2021
     13// Update Count     : 72
    1414//
    1515
    1616#include <fstream.hfa>
    1717#include <thread.hfa>
     18#include <mutex_stmt.hfa>
    1819
    1920thread T {};
     
    2122        // output from parallel threads should not be scrambled
    2223
    23         for ( 100 ) {                                                                           // local protection
    24                 sout | acquire | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
     24        for ( 100 ) {                                                                           // expression protection
     25                mutex(sout) sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
    2526        }
    26         {                                                                                                       // global protection (RAII)
    27                 osacquire acq = { sout };
     27        mutex( sout ) {                                                                         // statement protection
    2828                for ( 100 ) {
    2929                        sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
     
    3131        }
    3232        {                                                                                                       // duplicate protection demonstrating recursive lock
    33                 osacquire acq = { sout };
    34                 for ( 100 ) {
    35                         osacquire acq = { sout };
    36                         sout | acquire | 1 | 2 | 3 | 4 | 5 | acquire | 6 | 7 | 8 | 9;
    37                         sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
     33                ofstream & h1( ofstream & os ) {                                // helper
     34                        mutex( os ) return os | 1 | 2 | 3 | 4;          // unnecessary mutex
     35                }
     36                ofstream & h2( ofstream & os ) {                                // helper
     37                        mutex( os ) return os | 6 | 7 | 8 | 9;          // unnecessary mutex
     38                }
     39                mutex( sout ) {                                                                 // unnecessary mutex
     40                        for ( 100 ) {
     41                                mutex( sout ) {
     42                                        sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
     43                                        sout | h1 | 5 | h2;                                     // refactored code
     44                                }
     45                        }
    3846                }
    3947        }
     
    4250
    4351        int a, b, c, d, e, f, g, h, i;
    44         for ( 100 ) {                                                                           // local protection
    45                 sin | acquire | a | b | c | d | e | f | g | h | i;
     52        for ( 100 ) {                                                                           // expression protection
     53                mutex(sin) sin | a | b | c | d | e | f | g | h | i;
    4654        }
    47         {                                                                                                       // global protection (RAII)
    48                 isacquire acq = { sin };
     55        mutex( sin ) {                                                                          // statement protection
    4956                for ( 100 ) {
    5057                        sin  | a | b | c | d | e | f | g | h | i;
     
    5259        }
    5360        {                                                                                                       // duplicate protection demonstrating recursive lock
    54                 isacquire acq = { sin };
    55                 for ( 100 ) {
    56                         isacquire acq = { sin };
    57                         sin | acquire | a | b | c | d | e | acquire | f | g | h | i;
    58                         sin | a | b | c | d | e | f | g | h | i;
     61                ifstream & h1( ifstream & is ) {                                // helper
     62                        mutex( is ) return is | a | b | c | d;          // unnecessary mutex
     63                }
     64                ifstream & h2( ifstream & is ) {                                // helper
     65                        mutex( is ) return is | f | g | h | i;          // unnecessary mutex
     66                }
     67                mutex( sin ) {                                                                  // unnecessary mutex
     68                        for ( 5 ) {
     69                                mutex( sin ) {
     70                                        sin  | a | b | c | d | e | f | g | h | i;
     71                                        sin  | h1 | e | h2;                                     // refactored code
     72                                }
     73                        }
    5974                }
    6075        }
  • tests/linking/io-acquire.cfa

    r8dcb832 r237df76  
    1717#include <fstream.hfa>
    1818#include <stdlib.hfa>
     19#include <mutex_stmt.hfa>
    1920
    2021int main() {
    2122        int i;
    2223        if(threading_enabled()) {
    23                 stdout | acquire | "YES";
     24                mutex( stdout ) stdout | "YES";
    2425                stdin | i;
    2526        } else {
    26                 stdout | acquire | "NO";
     27                mutex( stdout ) stdout | "NO";
    2728                stdin | i;
    2829        }
Note: See TracChangeset for help on using the changeset viewer.