Changeset 6cb3e5d


Ignore:
Timestamp:
Mar 14, 2025, 3:44:18 AM (6 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
6f9f338
Parents:
98a5ee7
Message:

formatting. reduce experiment duration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/unified_locking/locks.cfa

    r98a5ee7 r6cb3e5d  
    1 #include <stdio.h>
     1#include <fstream.hfa>
    22#include <locks.hfa>
    33#include <stdlib.hfa>
    44#include <thread.hfa>
    55
    6 const unsigned int num_times = 50000;
     6const unsigned int num_times = 20_000;
    77
    88multiple_acquisition_lock m;
     
    2424
    2525void main( T_C_M_WS1 & ) {
    26         for (unsigned int i = 0; i < num_times; i++) {
    27                 lock(m);
    28                 if(empty(c_m) && i != num_times - 1) {
    29                         wait(c_m,m);
    30                 }else{
    31                         notify_one(c_m);
    32                 }
    33                 unlock(m);
    34         }
    35 }
     26        for ( unsigned int i = 0; i < num_times; i++ ) {
     27                lock( m );
     28                if ( empty( c_m ) && i != num_times - 1 ) {
     29                        wait( c_m,m );
     30                } else {
     31                        notify_one( c_m );
     32                } // for
     33                unlock( m );
     34        } // for
     35} // main
    3636
    3737thread T_C_M_WB1 {};
    3838
    3939void main( T_C_M_WB1 & ) {
    40         for (unsigned int i = 0; i < num_times; i++) {
    41                 lock(m);
    42                 if(counter(c_m) == 3 || i == num_times - 1) {
    43                         notify_all(c_m);
    44                 }else{
    45                         wait(c_m,m);
    46                 }
    47                 unlock(m);
    48         }
    49 }
     40        for ( unsigned int i = 0; i < num_times; i++ ) {
     41                lock( m );
     42                if ( counter( c_m ) == 3 || i == num_times - 1 ) {
     43                        notify_all( c_m );
     44                } else {
     45                        wait( c_m,m );
     46                } // if
     47                unlock( m );
     48        } // for
     49} // main
    5050
    5151thread T_C_S_WS1 {};
    5252
    5353void main( T_C_S_WS1 & ) {
    54         for (unsigned int i = 0; i < num_times; i++) {
    55                 lock(s);
    56                 if(empty(c_s) && i != num_times - 1) {
    57                         wait(c_s,s);
    58                 }else{
    59                         notify_one(c_s);
    60                 }
    61                 unlock(s);
    62         }
    63 }
     54        for ( unsigned int i = 0; i < num_times; i++ ) {
     55                lock( s );
     56                if ( empty( c_s ) && i != num_times - 1 ) {
     57                        wait( c_s,s );
     58                } else {
     59                        notify_one( c_s );
     60                } // if
     61                unlock( s );
     62        } // for
     63} // main
    6464
    6565thread T_C_S_WB1 {};
    6666
    6767void main( T_C_S_WB1 & ) {
    68         for (unsigned int i = 0; i < num_times; i++) {
    69                 lock(s);
    70                 if(counter(c_s) == 3 || i == num_times - 1) {
    71                         notify_all(c_s);
    72                 }else{
    73                         wait(c_s,s);
    74                 }
    75                 unlock(s);
    76         }
    77 }
     68        for ( unsigned int i = 0; i < num_times; i++ ) {
     69                lock( s );
     70                if ( counter( c_s ) == 3 || i == num_times - 1 ) {
     71                        notify_all( c_s );
     72                } else {
     73                        wait( c_s,s );
     74                } // if
     75                unlock( s );
     76        } // for
     77} // main
    7878
    7979thread T_C_L_WS1 {};
    8080
    8181void main( T_C_L_WS1 & ) {
    82         for (unsigned int i = 0; i < num_times; i++) {
    83                 lock(l);
    84                 if(empty(c_l) && i != num_times - 1) {
    85                         wait(c_l,l);
    86                 }else{
    87                         notify_one(c_l);
    88                 }
    89                 unlock(l);
    90         }
    91 }
     82        for ( unsigned int i = 0; i < num_times; i++ ) {
     83                lock( l );
     84                if ( empty( c_l ) && i != num_times - 1 ) {
     85                        wait( c_l,l );
     86                } else {
     87                        notify_one( c_l );
     88                } // if
     89                unlock( l );
     90        } // for
     91} // main
    9292
    9393thread T_C_L_WB1 {};
    9494
    9595void main( T_C_L_WB1 & ) {
    96         for (unsigned int i = 0; i < num_times; i++) {
    97                 lock(l);
    98                 if(counter(c_l) == 3 || i == num_times - 1) {
    99                         notify_all(c_l);
    100                 }else{
    101                         wait(c_l,l);
    102                 }
    103                 unlock(l);
    104         }
    105 }
     96        for ( unsigned int i = 0; i < num_times; i++ ) {
     97                lock( l );
     98                if ( counter( c_l ) == 3 || i == num_times - 1 ) {
     99                        notify_all( c_l );
     100                } else {
     101                        wait( c_l,l );
     102                } // if
     103                unlock( l );
     104        } // for
     105} // main
    106106
    107107thread T_F_C_F_WS1 {};
    108108
    109109void main( T_F_C_F_WS1 & ) {
    110         for (unsigned int i = 0; i < num_times; i++) {
    111                 lock(f);
    112                 if(empty(f_c_f) && i != num_times - 1) {
    113                         wait(f_c_f,f);
    114                 }else{
    115                         notify_one(f_c_f);
    116                 }
    117                 unlock(f);
    118         }
    119 }
     110        for ( unsigned int i = 0; i < num_times; i++ ) {
     111                lock( f );
     112                if ( empty( f_c_f ) && i != num_times - 1 ) {
     113                        wait( f_c_f,f );
     114                } else {
     115                        notify_one( f_c_f );
     116                } // if
     117                unlock( f );
     118        } // for
     119} // main
    120120
    121121thread T_C_O_WS1 {};
    122122
    123123void main( T_C_O_WS1 & ) {
    124         for (unsigned int i = 0; i < num_times; i++) {
    125                 lock(o);
    126                 if(empty(c_o) && i != num_times - 1) {
    127                         wait(c_o,o);
    128                 }else{
    129                         notify_one(c_o);
    130                 }
    131                 unlock(o);
    132         }
    133 }
     124        for ( unsigned int i = 0; i < num_times; i++ ) {
     125                lock( o );
     126                if ( empty( c_o ) && i != num_times - 1 ) {
     127                        wait( c_o,o );
     128                } else {
     129                        notify_one( c_o );
     130                } // if
     131                unlock( o );
     132        } // for
     133} // main
    134134
    135135thread T_C_O_WB1 {};
    136136
    137137void main( T_C_O_WB1 & ) {
    138         for (unsigned int i = 0; i < num_times; i++) {
    139                 lock(o);
    140                 if(counter(c_o) == 3 || i == num_times - 1) {
    141                         notify_all(c_o);
    142                 }else{
    143                         wait(c_o,o);
    144                 }
    145                 unlock(o);
    146         }
    147 }
     138        for ( unsigned int i = 0; i < num_times; i++ ) {
     139                lock( o );
     140                if ( counter( c_o ) == 3 || i == num_times - 1 ) {
     141                        notify_all( c_o );
     142                } else {
     143                        wait( c_o,o );
     144                } // if
     145                unlock( o );
     146        } // for
     147} // main
    148148
    149149thread T_C_M_WS2 {};
    150150
    151151void main( T_C_M_WS2 & ) {
    152         for (unsigned int i = 0; i < num_times; i++) {
    153                 lock(m);
    154                 lock(m);
    155                 lock(m);
    156                 if(empty(c_m) && i != num_times - 1) {
    157                         wait(c_m,m);
    158                 }else{
    159                         notify_one(c_m);
    160                 }
    161                 unlock(m);
    162                 unlock(m);
    163                 unlock(m);
    164         }
    165 }
     152        for ( unsigned int i = 0; i < num_times; i++ ) {
     153                lock( m );
     154                lock( m );
     155                lock( m );
     156                if ( empty( c_m ) && i != num_times - 1 ) {
     157                        wait( c_m,m );
     158                } else {
     159                        notify_one( c_m );
     160                } // if
     161                unlock( m );
     162                unlock( m );
     163                unlock( m );
     164        } // for
     165} // main
    166166
    167167thread T_C_O_WS2 {};
    168168
    169169void main( T_C_O_WS2 & ) {
    170         for (unsigned int i = 0; i < num_times; i++) {
    171                 lock(o);
    172                 lock(o);
    173                 lock(o);
    174                 if(empty(c_o) && i != num_times - 1) {
    175                         wait(c_o,o);
    176                 }else{
    177                         notify_one(c_o);
    178                 }
    179                 unlock(o);
    180                 unlock(o);
    181                 unlock(o);
    182         }
    183 }
     170        for ( unsigned int i = 0; i < num_times; i++ ) {
     171                lock( o );
     172                lock( o );
     173                lock( o );
     174                if ( empty( c_o ) && i != num_times - 1 ) {
     175                        wait( c_o,o );
     176                } else {
     177                        notify_one( c_o );
     178                } // if
     179                unlock( o );
     180                unlock( o );
     181                unlock( o );
     182        } // for
     183} // main
    184184
    185185thread T_C_NLW {};
    186186
    187187void main( T_C_NLW & ) {
    188         for (unsigned int i = 0; i < num_times; i++) {
    189                 wait(c_o);
    190         }
    191 }
     188        for ( unsigned int i = 0; i < num_times; i++ ) {
     189                wait( c_o );
     190        } // for
     191} // main
    192192
    193193thread T_C_NLS {};
    194194
    195195void main( T_C_NLS & ) {
    196         for (unsigned int i = 0; i < num_times; i++) {
    197                 while (empty(c_o)) { }
    198                 notify_one(c_o);
    199         }
    200 }
     196        for ( unsigned int i = 0; i < num_times; i++ ) {
     197                while ( empty( c_o )) { }
     198                notify_one( c_o );
     199        } // for
     200} // main
    201201
    202202thread T_C_S_WNF {};
    203203
    204204void main( T_C_S_WNF & ) {
    205         for (unsigned int i = 0; i < num_times; i++) {
    206                 lock(s);
    207                 if(empty(c_s) && i != num_times - 1) {
    208                         wait(c_s, s, 10);
    209                 }else{
    210                         if(!empty(c_s)) assert(front(c_s) == 10);
    211                         notify_one(c_s);
    212                 }
    213                 unlock(s);
    214         }
    215 }
     205        for ( unsigned int i = 0; i < num_times; i++ ) {
     206                lock( s );
     207                if ( empty( c_s ) && i != num_times - 1 ) {
     208                        wait( c_s, s, 10 );
     209                } else {
     210                        if (!empty( c_s )) assert( front( c_s ) == 10 );
     211                        notify_one( c_s );
     212                } // if
     213                unlock( s );
     214        } // for
     215} // main
    216216
    217217bool done = false;
     
    221221void main( T_C_NLWD & ) {
    222222        done = false;
    223         for (unsigned int i = 0; i < num_times/5; i++) {
    224                 if (i % 1000 == 0) printf("Iteration: %d\n", i);
    225                 wait(c_s, 1`ns);
    226         }
     223        for ( unsigned int i = 0; i < num_times/5; i++ ) {
     224                if ( i % 1000 == 0 ) sout | "Iteration:" | i;
     225                wait( c_s, 1`ns );
     226        } // for
    227227        done = true;
    228 }
     228} // main
    229229
    230230thread T_C_WDS {};
    231231
    232232void main( T_C_WDS & ) {
    233         for (unsigned int i = 0; i < num_times; i++) {
    234                 while (empty(c_s) && !done) { }
    235                 notify_one(c_s);
    236                 sleep(1`ns);
    237                 if(done) break;
    238         }
    239 }
     233        for ( unsigned int i = 0; i < num_times; i++ ) {
     234                while ( empty( c_s ) && !done ) { }
     235                notify_one( c_s );
     236                sleep( 1`ns );
     237                if ( done ) break;
     238        } // for
     239} // main
    240240
    241241thread T_C_LWD {};
     
    243243void main( T_C_LWD & ) {
    244244        done = false;
    245         for (unsigned int i = 0; i < num_times/5; i++) {
    246                 if (i % 1000 == 0) printf("Iteration: %d\n", i);
    247                 lock(s);
    248                 wait(c_s, s, 1`ns);
    249                 unlock(s);
    250         }
     245        for ( unsigned int i = 0; i < num_times/5; i++ ) {
     246                if ( i % 1000 == 0 ) sout | "Iteration:" | i;
     247                lock( s );
     248                wait( c_s, s, 1`ns );
     249                unlock( s );
     250        } // for
    251251        done = true;
    252 }
     252} // main
    253253
    254254thread T_C_LWDS {};
    255255
    256256void main( T_C_LWDS & ) {
    257         for (unsigned int i = 0; i < num_times; i++) {
    258                 while (empty(c_s) && !done) { }
    259                 lock(s);
    260                 notify_one(c_s);
    261                 unlock(s);
    262                 sleep(1`ns);
    263                 if(done) break;
    264         }
    265 }
     257        for ( unsigned int i = 0; i < num_times; i++ ) {
     258                while ( empty( c_s ) && !done ) { }
     259                lock( s );
     260                notify_one( c_s );
     261                unlock( s );
     262                sleep( 1`ns );
     263                if ( done ) break;
     264        } // for
     265} // main
    266266
    267267int main() {
    268268        processor p[2];
    269         printf("Start Test 1: multi acquisition lock and condition variable single wait/notify\n");
     269        sout | "Start Test 1: multi acquisition lock and condition variable single wait/notify";
    270270        {
    271271                T_C_M_WS1 t1[2];
    272272        }
    273         printf("Done Test 1\n");
    274 
    275         printf("Start Test 2: multi acquisition lock and condition variable 3 wait/notify all\n");
     273        sout | "Done Test 1";
     274
     275        sout | "Start Test 2: multi acquisition lock and condition variable 3 wait/notify all";
    276276        {
    277277                T_C_M_WB1 t1[4];
    278278        }
    279         printf("Done Test 2\n");
    280 
    281         printf("Start Test 3: single acquisition lock and condition variable single wait/notify\n");
     279        sout | "Done Test 2";
     280
     281        sout | "Start Test 3: single acquisition lock and condition variable single wait/notify";
    282282        {
    283283                T_C_S_WS1 t1[2];
    284284        }
    285         printf("Done Test 3\n");
    286 
    287         printf("Start Test 4: single acquisition lock and condition variable 3 wait/notify all\n");
     285        sout | "Done Test 3";
     286
     287        sout | "Start Test 4: single acquisition lock and condition variable 3 wait/notify all";
    288288        {
    289289                T_C_S_WB1 t1[4];
    290290        }
    291         printf("Done Test 4\n");
    292 
    293         printf("Start Test 5: owner lock and condition variable single wait/notify\n");
     291        sout | "Done Test 4";
     292
     293        sout | "Start Test 5: owner lock and condition variable single wait/notify";
    294294        {
    295295                T_C_O_WS1 t1[2];
    296296        }
    297         printf("Done Test 5\n");
    298 
    299         printf("Start Test 6: owner lock and condition variable 3 wait/notify all\n");
     297        sout | "Done Test 5";
     298
     299        sout | "Start Test 6: owner lock and condition variable 3 wait/notify all";
    300300        {
    301301                T_C_O_WB1 t1[4];
    302302        }
    303         printf("Done Test 6\n");
    304 
    305         printf("Start Test 7: linear backoff lock and condition variable single wait/notify\n");
     303        sout | "Done Test 6";
     304
     305        sout | "Start Test 7: linear backoff lock and condition variable single wait/notify";
    306306        {
    307307                T_C_L_WS1 t1[2];
    308308        }
    309         printf("Done Test 7\n");
    310 
    311         printf("Start Test 8: linear backoff lock and condition variable 3 wait/notify all\n");
     309        sout | "Done Test 7";
     310
     311        sout | "Start Test 8: linear backoff lock and condition variable 3 wait/notify all";
    312312        {
    313313                T_C_L_WB1 t1[4];
    314314        }
    315         printf("Done Test 8\n");
    316 
    317         printf("Start Test 9: multi acquisiton lock and condition variable multiple acquire and wait/notify\n");
     315        sout | "Done Test 8";
     316
     317        sout | "Start Test 9: multi acquisiton lock and condition variable multiple acquire and wait/notify";
    318318        {
    319319                T_C_M_WS2 t1[2];
    320320        }
    321         printf("Done Test 9\n");
    322 
    323         printf("Start Test 10: owner lock and condition variable multiple acquire and wait/notify\n");
     321        sout | "Done Test 9";
     322
     323        sout | "Start Test 10: owner lock and condition variable multiple acquire and wait/notify";
    324324        {
    325325                T_C_O_WS2 t1[2];
    326326        }
    327         printf("Done Test 10\n");
    328 
    329         printf("Start Test 11: no lock condition variable wait/notify\n");
     327        sout | "Done Test 10";
     328
     329        sout | "Start Test 11: no lock condition variable wait/notify";
    330330        {
    331331                T_C_NLW t1;
    332332                T_C_NLS t2;
    333333        }
    334         printf("Done Test 11\n");
    335 
    336         printf("Start Test 12: locked condition variable wait/notify with front()\n");
     334        sout | "Done Test 11";
     335
     336        sout | "Start Test 12: locked condition variable wait/notify with front()";
    337337        {
    338338                T_C_S_WNF t1[2];
    339339        }
    340         printf("Done Test 12\n");
    341 
    342         printf("Start Test 13: fast block lock and fast cond var single wait/notify\n");
     340        sout | "Done Test 12";
     341
     342        sout | "Start Test 13: fast block lock and fast cond var single wait/notify";
    343343        {
    344344                T_F_C_F_WS1 t1[2];
    345345        }
    346         printf("Done Test 13\n");
    347        
    348 }
     346        sout | "Done Test 13";
     347} // main
Note: See TracChangeset for help on using the changeset viewer.