Implement a solution to the critical section problem for 2


Implement a solution to the critical section problem for 2 processes using mutex locks. Specifically in pthreads using pthread_mutex_trylock.

You are provided with code in thread-template.c (available on the class hints web page) which does not work correctly, but has the necessary pthread Unix thread calls to start up two threads from the main process. Remember that all global memory is shared among threads of a process. Both threads need to count to 2,000,000 which means a correct overall count is 4,000,000. Threadl needs to be modified so that every time it sees (counter- > value%100) == 0 it increments counter- > value by 100. That counts for an 100 individual updates. You also need to keep track of how many times this happens and report it.

Use the POSIX implementation of threads. You will need to look at the pthread_create, pthread join and threads manual pages. A tutorial and the man pages are here: https://www.yolinux.com/TUTORIA LS /LinuxTutorialPosi xThreads. html

Time your code with getrusage. This is for a comparison project. It will look something like the following. The first four lines are what you need to set this up.

Attachment:- Assignment.rar

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Implement a solution to the critical section problem for 2
Reference No:- TGS02190490

Expected delivery within 24 Hours