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
        resolv-new
        with_gc
      
      
        
          | Last change
 on this file since dba6db9 was             f80ab45, checked in by Thierry Delisle <tdelisle@…>, 9 years ago | 
        
          | 
Internal scheduling tests
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            921 bytes | 
      
      
| Rev | Line |  | 
|---|
| [f80ab45] | 1 | #include <fstream> | 
|---|
| [5ea06d6] | 2 | #include <kernel> | 
|---|
|  | 3 | #include <monitor> | 
|---|
|  | 4 | #include <thread> | 
|---|
|  | 5 |  | 
|---|
|  | 6 | monitor global_t { | 
|---|
|  | 7 | int value; | 
|---|
|  | 8 | }; | 
|---|
|  | 9 |  | 
|---|
|  | 10 | global_t global; | 
|---|
|  | 11 |  | 
|---|
|  | 12 | condition cond; | 
|---|
|  | 13 |  | 
|---|
|  | 14 | thread Signalee {}; | 
|---|
|  | 15 | thread Signaler {}; | 
|---|
|  | 16 |  | 
|---|
|  | 17 | void step1( global_t * mutex this ) { | 
|---|
| [f80ab45] | 18 | sout | "Step 1" | endl; | 
|---|
| [5ea06d6] | 19 | this->value = 1; | 
|---|
|  | 20 | wait( &cond ); | 
|---|
|  | 21 | } | 
|---|
|  | 22 |  | 
|---|
|  | 23 | void step2( global_t * mutex this ) { | 
|---|
|  | 24 | if( this->value != 1) abort(); | 
|---|
|  | 25 |  | 
|---|
| [f80ab45] | 26 | sout | "Step 2" | endl; | 
|---|
| [5ea06d6] | 27 | this->value = 2; | 
|---|
|  | 28 | signal( &cond ); | 
|---|
|  | 29 | } | 
|---|
|  | 30 |  | 
|---|
|  | 31 | void step3( global_t * mutex this ) { | 
|---|
|  | 32 | if( this->value != 2) abort(); | 
|---|
|  | 33 |  | 
|---|
| [f80ab45] | 34 | sout | "Step 3" | endl; | 
|---|
|  | 35 | this->value = 3; | 
|---|
| [5ea06d6] | 36 | signal( &cond ); | 
|---|
|  | 37 | } | 
|---|
|  | 38 |  | 
|---|
|  | 39 | void main( Signalee* this ) { | 
|---|
|  | 40 | step1( &global ); | 
|---|
|  | 41 | step3( &global ); | 
|---|
|  | 42 | } | 
|---|
|  | 43 |  | 
|---|
|  | 44 | void main( Signaler* this ) { | 
|---|
|  | 45 | for(int i = 0; i < 10_000; i++) { | 
|---|
|  | 46 | asm volatile ("" : : : "memory"); | 
|---|
|  | 47 | } | 
|---|
|  | 48 |  | 
|---|
|  | 49 | step2( &global ); | 
|---|
|  | 50 | } | 
|---|
|  | 51 |  | 
|---|
|  | 52 | int main(int argc, char* argv[]) { | 
|---|
|  | 53 | assert( global.__mon.entry_queue.tail != NULL ); | 
|---|
|  | 54 | processor p; | 
|---|
|  | 55 | { | 
|---|
|  | 56 | Signalee a; | 
|---|
|  | 57 | Signaler b; | 
|---|
|  | 58 | } | 
|---|
|  | 59 | if( global.value != 3) abort(); | 
|---|
|  | 60 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.