source: doc/papers/concurrency/examples/Pingpong.py @ 53a49cc

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 53a49cc was a573c22, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

example programs updated for concurrency paper

  • Property mode set to 100644
File size: 731 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        try:
12                while True:
13                        n = next( n )           # schedule coroutine
14        except StopIteration:
15                pass
16
17pi = PingPong( "ping", 5 )
18po = PingPong( "pong", 5 )
19next( pi )                                              # prime
20pi.send( po )                                   # send partner
21next( po )                                              # prime
22po.send( pi )                                   # send partner
23
24s = Scheduler();
25next( s )                                               # prime
26try:
27        s.send( pi )                            # start cycle
28except StopIteration:                   # scheduler stopped
29        pass
30print( "stop" )
31
32# Local Variables: #
33# tab-width: 4 #
34# compile-command: "python3.7 Pingpong.py" #
35# End: #
Note: See TracBrowser for help on using the repository browser.