示例#1
0
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.")
示例#2
0
# 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     #
示例#3
0
# 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.")
示例#4
0
# 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     #