Ignore:
Timestamp:
Mar 21, 2022, 1:44:06 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
a76202d
Parents:
ef3c383 (diff), dbe2533 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/mutexstmt/locks.cfa

    ref3c383 rd672350  
    33
    44const unsigned int num_times = 10000;
     5
     6Duration default_preemption() { return 0; }
    57
    68single_acquisition_lock m1, m2, m3, m4, m5;
     
    2224}
    2325
     26void refTest( single_acquisition_lock & m ) {
     27        mutex ( m ) {
     28                assert(!insideFlag);
     29                insideFlag = true;
     30                assert(insideFlag);
     31                insideFlag = false;
     32        }
     33}
     34
    2435thread T_Multi {};
    2536
    2637void main( T_Multi & this ) {
    2738        for (unsigned int i = 0; i < num_times; i++) {
     39                refTest( m1 );
    2840                mutex ( m1 ) {
    2941                        assert(!insideFlag);
     
    5971}
    6072
    61 thread T_Mutex_Scoped {};
     73single_acquisition_lock l1;
     74linear_backoff_then_block_lock l2;
     75owner_lock l3;
    6276
    63 void main( T_Mutex_Scoped & this ) {
     77monitor monitor_t {};
     78
     79monitor_t l4;
     80
     81thread T_Multi_Poly {};
     82
     83void main( T_Multi_Poly & this ) {
    6484        for (unsigned int i = 0; i < num_times; i++) {
    65                 {
    66                         scoped_lock(single_acquisition_lock) s{m1};
    67                         count++;
    68                 }
    69                 {
    70                         scoped_lock(single_acquisition_lock) s{m1};
     85                refTest( l1 );
     86                mutex ( l1, l4 ) {
    7187                        assert(!insideFlag);
    7288                        insideFlag = true;
     
    7490                        insideFlag = false;
    7591                }
    76         }
    77 }
    78 
    79 thread T_Multi_Scoped {};
    80 
    81 void main( T_Multi_Scoped & this ) {
    82         for (unsigned int i = 0; i < num_times; i++) {
    83                 {
    84                         scoped_lock(single_acquisition_lock) s{m1};
     92                mutex ( l1, l2, l3 ) {
    8593                        assert(!insideFlag);
    8694                        insideFlag = true;
     
    8896                        insideFlag = false;
    8997                }
    90                 {
    91                         scoped_lock(single_acquisition_lock) s1{m1};
    92                         scoped_lock(single_acquisition_lock) s2{m2};
    93                         scoped_lock(single_acquisition_lock) s3{m3};
    94                         scoped_lock(single_acquisition_lock) s4{m4};
    95                         scoped_lock(single_acquisition_lock) s5{m5};
     98                mutex ( l3, l1, l4 ) {
    9699                        assert(!insideFlag);
    97100                        insideFlag = true;
     
    99102                        insideFlag = false;
    100103                }
    101                 {
    102                         scoped_lock(single_acquisition_lock) s1{m1};
    103                         scoped_lock(single_acquisition_lock) s3{m3};
    104                         assert(!insideFlag);
    105                         insideFlag = true;
    106                         assert(insideFlag);
    107                         insideFlag = false;
    108                 }
    109                 {
    110                         scoped_lock(single_acquisition_lock) s1{m1};
    111                         scoped_lock(single_acquisition_lock) s2{m2};
    112                         scoped_lock(single_acquisition_lock) s4{m4};
    113                         assert(!insideFlag);
    114                         insideFlag = true;
    115                         assert(insideFlag);
    116                         insideFlag = false;
    117                 }
    118                 {
    119                         scoped_lock(single_acquisition_lock) s1{m1};
    120                         scoped_lock(single_acquisition_lock) s3{m3};
    121                         scoped_lock(single_acquisition_lock) s4{m4};
    122                         scoped_lock(single_acquisition_lock) s5{m5};
     104                mutex ( l1, l2, l4 ) {
    123105                        assert(!insideFlag);
    124106                        insideFlag = true;
     
    131113int num_tasks = 10;
    132114int main() {
    133         processor p[10];
     115        processor p[num_tasks - 1];
    134116
    135117        printf("Start Test: single lock mutual exclusion\n");
    136118        {
    137                 T_Mutex t[10];
     119                T_Mutex t[num_tasks];
    138120        }
    139121        assert(count == num_tasks * num_times);
     
    141123        printf("Start Test: multi lock deadlock/mutual exclusion\n");
    142124        {
    143                 T_Multi t[10];
     125                T_Multi t[num_tasks];
    144126        }
    145127        printf("End Test: multi lock deadlock/mutual exclusion\n");
    146        
    147         count = 0;
    148         printf("Start Test: single scoped lock mutual exclusion\n");
     128        printf("Start Test: multi polymorphic lock deadlock/mutual exclusion\n");
    149129        {
    150                 T_Mutex_Scoped t[10];
     130                T_Multi_Poly t[num_tasks];
    151131        }
    152         assert(count == num_tasks * num_times);
    153         printf("End Test: single scoped lock mutual exclusion\n");
    154         printf("Start Test: multi scoped lock deadlock/mutual exclusion\n");
    155         {
    156                 T_Multi_Scoped t[10];
    157         }
    158         printf("End Test: multi scoped lock deadlock/mutual exclusion\n");     
     132        printf("End Test: multi polymorphic lock deadlock/mutual exclusion\n");
    159133}
Note: See TracChangeset for help on using the changeset viewer.