Question: Need help with the following C++ program. The program itself deals with mutexes and locks but I can not figure out how to increment the
Need help with the following C++ program. The program itself deals with mutexes and locks but I can not figure out how to increment the output correctly.
The output should look like something like:
Thread 1: Incrementing counter. Current value: 1
Thread 2: Incrementing counter. Current value: 2
Thread 1: Incrementing counter. Current value: 3
Thread 2: Incrementing counter. Current value: 4
etc...
Instead my output looks like:

Thread 1: Incrementing counter. Current value: 1 Thread 1: Incrementing counter. Current value: 2 Thread 1: Incrementing counter. Current value: 3 Thread 1: Incrementing counter. Current value: 4 Thread 2: Incrementing counter. Current value: 5 Thread 2: Incrementing counter. Current value: 6 Thread 2: Incrementing counter. Current value: 7 Thread 2: Incrementing counter. Current value: 8 Thread 2: Incrementing counter. Current value: 9 Thread 1: Incrementing counter. Current value: 10 Final counter value:10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
