ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since 341bb80 was             73abe95, checked in by Thierry Delisle <tdelisle@…>, 7 years ago | 
        
          | 
Replace extension-less headers with .hfa
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.6 KB | 
      
      
| Line |  | 
|---|
| 1 | #include <fstream.hfa> | 
|---|
| 2 | #include <kernel.hfa> | 
|---|
| 3 | #include <monitor.hfa> | 
|---|
| 4 | #include <stdlib.hfa> | 
|---|
| 5 | #include <thread.hfa> | 
|---|
| 6 |  | 
|---|
| 7 | #include <time.h> | 
|---|
| 8 |  | 
|---|
| 9 | static const unsigned long N = 500ul; | 
|---|
| 10 |  | 
|---|
| 11 | #ifndef PREEMPTION_RATE | 
|---|
| 12 | #define PREEMPTION_RATE 10`ms | 
|---|
| 13 | #endif | 
|---|
| 14 |  | 
|---|
| 15 | Duration default_preemption() { | 
|---|
| 16 | return PREEMPTION_RATE; | 
|---|
| 17 | } | 
|---|
| 18 |  | 
|---|
| 19 | monitor global_t {}; | 
|---|
| 20 |  | 
|---|
| 21 | global_t globalA; | 
|---|
| 22 |  | 
|---|
| 23 | thread Acceptor {}; | 
|---|
| 24 | thread Acceptee {}; | 
|---|
| 25 |  | 
|---|
| 26 | volatile bool done; | 
|---|
| 27 |  | 
|---|
| 28 | //---------------------------------------------------------------------------------------------------- | 
|---|
| 29 | // Acceptor | 
|---|
| 30 | void do_notify( global_t * mutex a ); | 
|---|
| 31 |  | 
|---|
| 32 | void do_wait( global_t * mutex a ) { | 
|---|
| 33 | sout | "Waiting to accept" | endl; | 
|---|
| 34 | yield( random( 10 ) ); | 
|---|
| 35 |  | 
|---|
| 36 | sout | "Accepting" | endl; | 
|---|
| 37 |  | 
|---|
| 38 | __acceptable_t acceptable; | 
|---|
| 39 | acceptable.func          = (fptr_t)do_notify; | 
|---|
| 40 | acceptable.count         = 1; | 
|---|
| 41 | acceptable.monitors      = &a; | 
|---|
| 42 |  | 
|---|
| 43 | __waitfor_internal( 1, &acceptable ); | 
|---|
| 44 |  | 
|---|
| 45 | sout | "Accepted" | endl; | 
|---|
| 46 | yield( random( 10 ) ); | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | void main( Acceptor* this ) { | 
|---|
| 50 | for( int i = 0; i < N; i++ ) { | 
|---|
| 51 | do_wait( &globalA ); | 
|---|
| 52 | sout | i | endl; | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | done = true; | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | //---------------------------------------------------------------------------------------------------- | 
|---|
| 59 | // Acceptee | 
|---|
| 60 | void do_notify( global_t * mutex a ) { | 
|---|
| 61 |  | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | void main( Acceptee* this ) { | 
|---|
| 65 | while( !done ) { | 
|---|
| 66 | yield( random( 10 ) ); | 
|---|
| 67 | do_notify( &globalA ); | 
|---|
| 68 | yield( random( 10 ) ); | 
|---|
| 69 | } | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | //---------------------------------------------------------------------------------------------------- | 
|---|
| 73 | // Main | 
|---|
| 74 | int main(int argc, char* argv[]) { | 
|---|
| 75 | done = false; | 
|---|
| 76 | srandom( time( NULL ) ); | 
|---|
| 77 | printf("%p\n", &globalA); | 
|---|
| 78 | sout | "Starting" | endl; | 
|---|
| 79 | { | 
|---|
| 80 | Acceptor r; | 
|---|
| 81 | Acceptee e[13]; | 
|---|
| 82 |  | 
|---|
| 83 | } | 
|---|
| 84 | sout | "Done" | endl; | 
|---|
| 85 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.