Question: Please help, I need the threads to print in order of ID , along with preventing another thread from starting until the first is complete.
Please help, I need the threads to print in order of ID along with preventing another thread from starting until the first is complete. I have it setup so that it will prevent another from starting, however they are not printing on numerical order from the ID I added a photo of the instructions as well as my current output.
Here is part of my code:
case :
Run Type Same as run type but threads must execute their work in order of thread ID
You are required to use a conditional variable for run type
for int i ; i threadDatanumberOfStringsToGenerate; i
loop through thread count
for int j ; j threadCount; j
if j is equal to thread data id
if j threadDataid
std::uniquelock lockmutexVar;
freeze thread
std::thisthread::sleepforstd::chrono::milliseconds;
loop through thread data string length
for int k ; k threadDatasharedStringLength; k
create string using thread data
threadDatasharedStringkA threadDataid;
print thread
printfThread d: s
threadDataid threadDatasharedString;
break;
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
