Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Whom to ask questions about book content?

Hi,

If I have the question to the author regarding the book content, what do I do?

Parallel Programming in Python - Jan Palach.

Question:
What is the point of using Condition together with Queue (in book example or in general)?
For example why not to solve the problem just with the Queue, as the queue already implements the locking mechanisms.

fibo_dict = {}
shared_queue = Queue()
input_list = [3, 10, 5, 7]
def fibonacci_task(shared_queue):
logger.info("Waiting - {}".format(threading.current_thread().name))
value = shared_queue.get()
a, b = 0, 1
for item in range(value):
a, b = b, a + b
fibo_dict[value] = a
shared_queue.task_done()
logger.info("{} fibonacci of key {} with result {}".format(threading.current_thread().name, value, fibo_dict[value]))
def queue_task(shared_queue):
logging.info('Starting queue_task...')
for item in input_list:
shared_queue.put(item)
logger.info('Notifying fibonacci task threads that the queue is ready to consume...')
threads = [threading.Thread(target=fibonacci_task, args=(shared_queue,)) for i in range(4)]
for thread in threads:
thread.daemon = True
thread.start()
prod = threading.Thread(target=queue_task, name='queue_task_thread', args=(shared_queue,))
prod.start()

Best regards,
Jegor
1 person has
this question
+1
Reply