ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since b408364 was
1e5d0f0c,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
start rewrite of coroutine section
|
-
Property mode set to
100644
|
File size:
826 bytes
|
Line | |
---|
1 | def PingPong( name, N ): |
---|
2 | partner = (yield) # get partner |
---|
3 | yield # resume scheduler |
---|
4 | for i in range( N ): |
---|
5 | print( name ) |
---|
6 | yield partner # execute next |
---|
7 | print( "end", name ) |
---|
8 | |
---|
9 | def Scheduler(): |
---|
10 | n = (yield) # starting coroutine |
---|
11 | while True: |
---|
12 | n = next( n ) # schedule coroutine |
---|
13 | |
---|
14 | pi = PingPong( "ping", 5 ) |
---|
15 | po = PingPong( "pong", 5 ) |
---|
16 | next( pi ) # prime |
---|
17 | pi.send( po ) # send partner |
---|
18 | next( po ) # prime |
---|
19 | po.send( pi ) # send partner |
---|
20 | |
---|
21 | s = Scheduler(); |
---|
22 | next( s ) # prime |
---|
23 | try: |
---|
24 | s.send( pi ) # start cycle |
---|
25 | except StopIteration: |
---|
26 | print( "scheduler stop" ) |
---|
27 | print( "stop" ) |
---|
28 | |
---|
29 | # Local Variables: # |
---|
30 | # tab-width: 4 # |
---|
31 | # compile-command: "python3.5 Pingpong.py" # |
---|
32 | # End: # |
---|
Note: See
TracBrowser
for help on using the repository browser.