Question: 1 . Write code that spawns 3 0 parallel threads. Each thread is executing the print function. Please end the main program when all threads
Write code that spawns parallel threads. Each thread is executing the print function. Please end the main program when all threads spawned are
finished. Submit two source files, one in which a lock guard is used to protect each iteration
of the for loop in print, and one where no mutex or lock guard is used. Submit also screen
shots with the execution of the two programs. Hint: store thread objects in an array.
Write a program that spawns parallel threads. Two of the threads use one queue data
structure the same queue to insert randomly generated integers. The other two, extract
the integers from the queue. Protect the Queue with a mutex managed by a lock guard.
The inserting threads should generate integers each. After generating the integers, the
generating threads should end. Design a mechanism by which the extracting threads end their
execution when no more data is inserted by the generating threads because they terminated.
Output appropriate messages to identify each operation with the queue and reveal which
thread executes it
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
