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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started