ADT
        ast-experimental
        enum
        forall-pointer-decay
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since 96f01d7f was             bbe3719, checked in by caparsons <caparson@…>, 4 years ago           | 
        
        
          | 
             
cleaned up some mutex stmt related code 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.4 KB
           | 
        
      
      
| Rev | Line |   | 
|---|
| [af67ee1] | 1 | #include <mutex_stmt.hfa>
 | 
|---|
| [a4d098c] | 2 | #include <locks.hfa>
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | const unsigned int num_times = 10000;
 | 
|---|
 | 5 | 
 | 
|---|
| [bbe3719] | 6 | single_acquisition_lock m1, m2, m3, m4, m5;
 | 
|---|
| [a4d098c] | 7 | 
 | 
|---|
 | 8 | thread T_Mutex {};
 | 
|---|
 | 9 | bool insideFlag = false;
 | 
|---|
 | 10 | int count = 0;
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | void main( T_Mutex & this ) {
 | 
|---|
 | 13 |         for (unsigned int i = 0; i < num_times; i++) {
 | 
|---|
 | 14 |                 mutex ( m1 ) count++;
 | 
|---|
| [af67ee1] | 15 |                 mutex ( m1 ) { 
 | 
|---|
| [a4d098c] | 16 |                         assert(!insideFlag);
 | 
|---|
 | 17 |                         insideFlag = true;
 | 
|---|
 | 18 |                         assert(insideFlag);
 | 
|---|
 | 19 |                         insideFlag = false;
 | 
|---|
 | 20 |                 }
 | 
|---|
 | 21 |         }
 | 
|---|
 | 22 | }
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | thread T_Multi {};
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | void main( T_Multi & this ) {
 | 
|---|
 | 27 |         for (unsigned int i = 0; i < num_times; i++) {
 | 
|---|
 | 28 |                 mutex ( m1 ) {
 | 
|---|
 | 29 |                         assert(!insideFlag);
 | 
|---|
 | 30 |                         insideFlag = true;
 | 
|---|
 | 31 |                         assert(insideFlag);
 | 
|---|
 | 32 |                         insideFlag = false;
 | 
|---|
 | 33 |                 }
 | 
|---|
 | 34 |                 mutex ( m1, m2, m3, m4, m5 ) {
 | 
|---|
 | 35 |                         assert(!insideFlag);
 | 
|---|
 | 36 |                         insideFlag = true;
 | 
|---|
 | 37 |                         assert(insideFlag);
 | 
|---|
 | 38 |                         insideFlag = false;
 | 
|---|
 | 39 |                 }
 | 
|---|
 | 40 |                 mutex ( m3, m1 ) {
 | 
|---|
 | 41 |                         assert(!insideFlag);
 | 
|---|
 | 42 |                         insideFlag = true;
 | 
|---|
 | 43 |                         assert(insideFlag);
 | 
|---|
 | 44 |                         insideFlag = false;
 | 
|---|
 | 45 |                 }
 | 
|---|
 | 46 |                 mutex ( m1, m2, m4 ) {
 | 
|---|
 | 47 |                         assert(!insideFlag);
 | 
|---|
 | 48 |                         insideFlag = true;
 | 
|---|
 | 49 |                         assert(insideFlag);
 | 
|---|
 | 50 |                         insideFlag = false;
 | 
|---|
 | 51 |                 }
 | 
|---|
 | 52 |                 mutex ( m1, m3, m4, m5 ) {
 | 
|---|
 | 53 |                         assert(!insideFlag);
 | 
|---|
 | 54 |                         insideFlag = true;
 | 
|---|
 | 55 |                         assert(insideFlag);
 | 
|---|
 | 56 |                         insideFlag = false;
 | 
|---|
 | 57 |                 }
 | 
|---|
 | 58 |         }
 | 
|---|
 | 59 | }
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 | int main() {
 | 
|---|
 | 63 |         processor p[10];
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |         printf("Start Test: single lock mutual exclusion\n");
 | 
|---|
 | 66 |         {
 | 
|---|
| [bbe3719] | 67 |                 T_Mutex t[10];
 | 
|---|
| [a4d098c] | 68 |         }
 | 
|---|
 | 69 |         printf("End Test: single lock mutual exclusion\n");
 | 
|---|
 | 70 |         printf("Start Test: multi lock deadlock/mutual exclusion\n");
 | 
|---|
 | 71 |         {
 | 
|---|
 | 72 |                 T_Multi t[10];
 | 
|---|
 | 73 |         }
 | 
|---|
 | 74 |         printf("End Test: multi lock deadlock/mutual exclusion\n");
 | 
|---|
 | 75 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.