Question: C++ Write a program in which two threads works. Thread code should be placed in the function Function parameter is the thread number (Integer number).

C++

Write a program in which two threads works. Thread code should be placed in the function Function parameter is the thread number (Integer number). Thread displays in the loop 10 times the message

"i = number from 0 to 9, number = thread number". After displaying each message thread sleeps for 100 to 500 ms (random value) Synchronize operations on the console (use mutex and lock).

Thread code function

Creating threads, waiting for threads

Passing parameters to a thread

IO synchronization

Speelping thread for a random time

Modify the program from the above exercise so that the program has a group of 10 threads. Modify the text displayed by the thread so that it has the form:

"1 = number from 0 to 9 number thread number id = thread identifier". Use a semaphore instead of a mutex to synchronize operations on the console. Cause (also using the semaphore) that maximum 3 threads at a time could perform their action in for loop

Create a thread group, wait for threads

Passing parameters to threads (function bind()

Additionally display the thread identifier

Using a semaphore to limit the number of concurrent threads

Using a semaphore for IO synchronization

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!