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 d3e4d6c was             83a071f9, checked in by Rob Schluntz <rschlunt@…>, 8 years ago | 
        
          | 
Fix concurrency library, tests, and keywords for references
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            652 bytes | 
      
      
| Line |  | 
|---|
| 1 | #include <fstream> | 
|---|
| 2 | #include <kernel> | 
|---|
| 3 | #include <monitor> | 
|---|
| 4 | #include <thread> | 
|---|
| 5 |  | 
|---|
| 6 | monitor global_t { | 
|---|
| 7 | int value; | 
|---|
| 8 | }; | 
|---|
| 9 |  | 
|---|
| 10 | void ?{}(global_t & this) { | 
|---|
| 11 | this.value = 0; | 
|---|
| 12 | } | 
|---|
| 13 |  | 
|---|
| 14 | static global_t global; | 
|---|
| 15 |  | 
|---|
| 16 | void increment3( global_t & mutex this ) { | 
|---|
| 17 | this.value += 1; | 
|---|
| 18 | } | 
|---|
| 19 |  | 
|---|
| 20 | void increment2( global_t & mutex this ) { | 
|---|
| 21 | increment3( this ); | 
|---|
| 22 | } | 
|---|
| 23 |  | 
|---|
| 24 | void increment( global_t & mutex this ) { | 
|---|
| 25 | increment2( this ); | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | thread MyThread {}; | 
|---|
| 29 |  | 
|---|
| 30 | void main( MyThread & this ) { | 
|---|
| 31 | for(int i = 0; i < 1_000_000; i++) { | 
|---|
| 32 | increment( global ); | 
|---|
| 33 | } | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | int main(int argc, char* argv[]) { | 
|---|
| 37 | assert( global.__mon.entry_queue.tail != NULL ); | 
|---|
| 38 | processor p; | 
|---|
| 39 | { | 
|---|
| 40 | MyThread f[4]; | 
|---|
| 41 | } | 
|---|
| 42 | sout | global.value | endl; | 
|---|
| 43 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.