예제 #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
파일: fig19_12.py 프로젝트: alannet/example
# 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     #