ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since fd642d2 was             1e5d0f0c, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago | 
        
          | 
start rewrite of coroutine section
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1002 bytes | 
      
      
| Line |  | 
|---|
| 1 | def Prod( N ): | 
|---|
| 2 | cons = (yield)              # get cons | 
|---|
| 3 | yield                       # resume scheduler | 
|---|
| 4 | for i in range( N ): | 
|---|
| 5 | print( "prod" ) | 
|---|
| 6 | yield cons              # execute next | 
|---|
| 7 | print( "end", "prod" ) | 
|---|
| 8 |  | 
|---|
| 9 | def Cons( N ): | 
|---|
| 10 | prod = (yield)              # get prod | 
|---|
| 11 | yield                       # resume scheduler | 
|---|
| 12 | for i in range( N ): | 
|---|
| 13 | print( "cons" ) | 
|---|
| 14 | yield prod              # execute next | 
|---|
| 15 | print( "end", "cons" ) | 
|---|
| 16 |  | 
|---|
| 17 | def Scheduler(): | 
|---|
| 18 | n = (yield)                 # starting coroutine | 
|---|
| 19 | while True: | 
|---|
| 20 | n = next( n )           # schedule coroutine | 
|---|
| 21 |  | 
|---|
| 22 | prod = Prod( 5 ) | 
|---|
| 23 | cons = Cons( 5 ) | 
|---|
| 24 | next( prod )                    # prime | 
|---|
| 25 | prod.send( cons )               # send cons | 
|---|
| 26 | next( cons )                    # prime | 
|---|
| 27 | cons.send( prod )               # send prod | 
|---|
| 28 |  | 
|---|
| 29 | s = Scheduler(); | 
|---|
| 30 | next( s )                       # prime | 
|---|
| 31 | try: | 
|---|
| 32 | s.send( prod )                          # start cycle | 
|---|
| 33 | except StopIteration: | 
|---|
| 34 | print( "scheduler stop" ) | 
|---|
| 35 | print( "stop" ) | 
|---|
| 36 |  | 
|---|
| 37 | # Local Variables: # | 
|---|
| 38 | # tab-width: 4 # | 
|---|
| 39 | # compile-command: "python3.5 ProdCons.py" # | 
|---|
| 40 | # End: # | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.