source: doc/papers/concurrency/examples/Pingpong.py @ b408364

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@…>, 6 years ago

start rewrite of coroutine section

  • Property mode set to 100644
File size: 826 bytes
Line 
1def 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
9def Scheduler():
10        n = (yield)                 # starting coroutine
11        while True:
12                n = next( n )           # schedule coroutine
13
14pi = PingPong( "ping", 5 )
15po = PingPong( "pong", 5 )
16next( pi )                      # prime
17pi.send( po )                   # send partner
18next( po )                      # prime
19po.send( pi )                   # send partner
20
21s = Scheduler();
22next( s )                       # prime
23try:
24        s.send( pi )                            # start cycle
25except StopIteration:
26        print( "scheduler stop" )
27print( "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.