I have a small program that runs 2 threads on the same critical section and uses mutex. The program works fine. But I would like to draw a UML, referably activity or state diagram, illustrating that the 2 threads runs the same critical section, not different parts of the codes. Please help me revise my UML.
Below is the source code:
#include <iostream>
#include <thread>
#include <mutex>
#include <stdio.h>
/* Global variables where both threads have access to*/
std::mutex myMutex;
int globalVariable = 1;
/* CRITICAL SECTION */
void hello()
{
myMutex.lock();
for (int counter =0 ; counter< 100; counter++){
//std::lock_guard<std::mutex> lock(myMutex);
printf("%d ",std::this_thread::get_id() ); //print the id of the thread that executes the for loop
globalVariable++;
}
printf("Thread with id = %d runs. Counter is %d \n", std::this_thread::get_id(), msg) ; //print the result counter value and thread id that finishes the for loop
myMutex.unlock();
}
int main()
{
std::thread t1(hello);
std::thread t2(hello);
t1.join();
t2.join();







