ADTast-experimental
Last change
on this file since 7b53bfd was
7bef8cf,
checked in by Peter A. Buhr <pabuhr@…>, 18 months ago
|
start paper on llheap
|
-
Property mode set to
100644
|
File size:
871 bytes
|
Rev | Line | |
---|
[7bef8cf] | 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 | try: |
---|
| 20 | while True: |
---|
| 21 | n = next( n ) # schedule coroutine |
---|
| 22 | except StopIteration: |
---|
| 23 | pass |
---|
| 24 | |
---|
| 25 | prod = Prod( 5 ) |
---|
| 26 | cons = Cons( 5 ) |
---|
| 27 | next( prod ) # prime |
---|
| 28 | prod.send( cons ) # send cons |
---|
| 29 | next( cons ) # prime |
---|
| 30 | cons.send( prod ) # send prod |
---|
| 31 | |
---|
| 32 | s = Scheduler(); |
---|
| 33 | next( s ) # prime |
---|
| 34 | try: |
---|
| 35 | s.send( prod ) # start cycle |
---|
| 36 | except StopIteration: # scheduler stopped |
---|
| 37 | pass |
---|
| 38 | print( "stop" ) |
---|
| 39 | |
---|
| 40 | # Local Variables: # |
---|
| 41 | # tab-width: 4 # |
---|
| 42 | # compile-command: "python3.7 ProdCons.py" # |
---|
| 43 | # End: # |
---|
Note: See
TracBrowser
for help on using the repository browser.