Ignore:
Timestamp:
Mar 27, 2019, 11:09:23 AM (5 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
a45fc7b
Parents:
2b10f95 (diff), 1e5d0f0c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/concurrency/examples/Pingpong.py

    r2b10f95 r86fb8f2  
    1 def Scheduler
     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
    223try:
    3         yield from ping();
    4         yield from pong();
     24        s.send( pi )                            # start cycle
    525except StopIteration:
    6         print( "Scheduler stop" )
    7 
    8 
    9 def pong():
    10         print( "pong" )
    11 for i in range( 10 ):
    12 
    13                 yield from ping()
    14         print( "stop pong" )
    15 
    16 def ping():
    17         global i
    18         print( "ping" )
    19         i += 1
    20         if i < 5:
    21                 yield from pong()
    22         print( "stop ping" )
    23 
    24 p = ping()
    25 try:
    26         next( p )
    27 except StopIteration:
    28         print( "stop" )
     26        print( "scheduler stop" )
     27print( "stop" )
    2928
    3029# Local Variables: #
    3130# tab-width: 4 #
    32 # compile-command: "python3.5 pingpong.py" #
     31# compile-command: "python3.5 Pingpong.py" #
    3332# End: #
Note: See TracChangeset for help on using the changeset viewer.