def main(): '''initialize integer and threads''' number = SynchronizedCells() producer = ProduceInteger("Producer", number) consumer = ConsumeInteger("Consumer", number) print("Start threads...\n") producer.start() consumer.start() # wait for threads to terminate producer.join() consumer.join() print("\nAll threads have terminated.")
# Fig. 19.12: fig19_12.py # Show multiple threads modifying shared object. from CircularBuffer import CircularBuffer from ProduceInteger import ProduceInteger from ConsumeInteger import ConsumeInteger # initialize number and threads buffer = CircularBuffer() producer = ProduceInteger( "Producer", buffer, 11, 20 ) consumer = ConsumeInteger( "Consumer", buffer, 10 ) print "Starting threads...\n" buffer.displayState() # start threads producer.start() consumer.start() # wait for threads to terminate producer.join() consumer.join() print "\nAll threads have terminated." ########################################################################## # (C) Copyright 2002 by Deitel & Associates, Inc. and Prentice Hall. # # All Rights Reserved. # # # # DISCLAIMER: The authors and publisher of this book have used their #
# In[8] : # program # menunjukkan multiple thread mengakses shared object from UnsynchronizedInteger import UnsynchronizedInteger from ProduceInteger import ProduceInteger from ConsumeInteger import ConsumeInteger # initialize integer and threads number = UnsynchronizedInteger() producer = ProduceInteger("Producer", number) consumer = ConsumeInteger("Consumer", number) print("Starting threads...\n") # start threads producer.start() consumer.start() # wait for threads to terminate producer.join() consumer.join() print("\nAll threads have terminated.")
# Fig. 19.12: fig19_12.py # Show multiple threads modifying shared object. from CircularBuffer import CircularBuffer from ProduceInteger import ProduceInteger from ConsumeInteger import ConsumeInteger # initialize number and threads buffer = CircularBuffer() producer = ProduceInteger("Producer", buffer, 11, 20) consumer = ConsumeInteger("Consumer", buffer, 10) print "Starting threads...\n" buffer.displayState() # start threads producer.start() consumer.start() # wait for threads to terminate producer.join() consumer.join() print "\nAll threads have terminated." ########################################################################## # (C) Copyright 2002 by Deitel & Associates, Inc. and Prentice Hall. # # All Rights Reserved. # # # # DISCLAIMER: The authors and publisher of this book have used their #