Changeset a573c22 for doc/papers/concurrency/examples/Pingpong.py
- Timestamp:
- Feb 6, 2020, 10:27:01 AM (3 years ago)
- Branches:
- arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 53a49cc
- Parents:
- b0795be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/Pingpong.py
rb0795be ra573c22 1 1 def PingPong( name, N ): 2 partner = (yield)# get partner3 yield 2 partner = yield # get partner 3 yield # resume scheduler 4 4 for i in range( N ): 5 5 print( name ) 6 yield partner 6 yield partner # execute next 7 7 print( "end", name ) 8 8 9 9 def Scheduler(): 10 n = (yield) # starting coroutine 11 while True: 12 n = next( n ) # schedule coroutine 10 n = yield # starting coroutine 11 try: 12 while True: 13 n = next( n ) # schedule coroutine 14 except StopIteration: 15 pass 13 16 14 17 pi = PingPong( "ping", 5 ) 15 18 po = PingPong( "pong", 5 ) 16 next( pi ) 17 pi.send( po ) 18 next( po ) 19 po.send( pi ) 19 next( pi ) # prime 20 pi.send( po ) # send partner 21 next( po ) # prime 22 po.send( pi ) # send partner 20 23 21 24 s = Scheduler(); 22 next( s ) 25 next( s ) # prime 23 26 try: 24 27 s.send( pi ) # start cycle 25 except StopIteration: 26 p rint( "scheduler stop" )28 except StopIteration: # scheduler stopped 29 pass 27 30 print( "stop" ) 28 31 29 32 # Local Variables: # 30 33 # tab-width: 4 # 31 # compile-command: "python3. 5Pingpong.py" #34 # compile-command: "python3.7 Pingpong.py" # 32 35 # End: #
Note: See TracChangeset
for help on using the changeset viewer.