ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        with_gc
      
      
        
          | 
            Last change
 on this file since 98278b3a was             0aa1b89, checked in by Thierry Delisle <tdelisle@…>, 8 years ago           | 
        
        
          | 
             
Renamed concurrent tests 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.5 KB
           | 
        
      
      
| Line |   | 
|---|
| 1 | //---------------------------------------------------------
 | 
|---|
| 2 | // Barging test
 | 
|---|
| 3 | // Ensures the statement order is reverse when using waitfor ^?{}
 | 
|---|
| 4 | //---------------------------------------------------------
 | 
|---|
| 5 | 
 | 
|---|
| 6 | #include <fstream>
 | 
|---|
| 7 | #include <kernel>
 | 
|---|
| 8 | #include <monitor>
 | 
|---|
| 9 | #include <stdlib>
 | 
|---|
| 10 | #include <thread>
 | 
|---|
| 11 | 
 | 
|---|
| 12 | #include <stdbool.h>
 | 
|---|
| 13 | 
 | 
|---|
| 14 | static const unsigned long N = 5_000ul;
 | 
|---|
| 15 | 
 | 
|---|
| 16 | enum state_t {
 | 
|---|
| 17 |         CTOR,
 | 
|---|
| 18 |         MAIN,
 | 
|---|
| 19 |         AFTER,
 | 
|---|
| 20 |         END,
 | 
|---|
| 21 |         DTOR
 | 
|---|
| 22 | };
 | 
|---|
| 23 | 
 | 
|---|
| 24 | thread dummy_t {
 | 
|---|
| 25 |         state_t state;
 | 
|---|
| 26 | };
 | 
|---|
| 27 | 
 | 
|---|
| 28 | static inline void set_state( dummy_t & this, state_t state) {
 | 
|---|
| 29 |         switch(state) {
 | 
|---|
| 30 |                 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;
 | 
|---|
| 35 |         }
 | 
|---|
| 36 | }
 | 
|---|
| 37 | 
 | 
|---|
| 38 | void ^?{}( dummy_t & mutex this ) {
 | 
|---|
| 39 |         set_state( this, DTOR );
 | 
|---|
| 40 | }
 | 
|---|
| 41 | 
 | 
|---|
| 42 | void ?{}( dummy_t & this ) {
 | 
|---|
| 43 |         this.state = CTOR;
 | 
|---|
| 44 | }
 | 
|---|
| 45 | 
 | 
|---|
| 46 | void main( dummy_t & this ) {
 | 
|---|
| 47 |         yield(random( 10 ));
 | 
|---|
| 48 |         set_state( this, MAIN );
 | 
|---|
| 49 |         waitfor( ^?{}, this ) {
 | 
|---|
| 50 |                 set_state( this, AFTER );
 | 
|---|
| 51 |         }
 | 
|---|
| 52 |         set_state( this, END );
 | 
|---|
| 53 | }
 | 
|---|
| 54 | 
 | 
|---|
| 55 | int main() {
 | 
|---|
| 56 |         sout | "Starting" | endl;
 | 
|---|
| 57 |         processor p;
 | 
|---|
| 58 |         for( int i = 0; i < N; i++ ){
 | 
|---|
| 59 |                 dummy_t dummy[4];
 | 
|---|
| 60 |                 yield( random( 100 ) );
 | 
|---|
| 61 |         }
 | 
|---|
| 62 |         sout | "Stopping" | endl;
 | 
|---|
| 63 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.