Question
Implement a solution to the critical section problem for 2 threads using mutex locks. Specifically, in pthreads using pthread mutex trylock. You will need to
Implement a solution to the critical section problem for 2 threads using mutex locks. Specifically, in pthreads using pthread mutex trylock. You will need to use 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,500,000 which means a correct overall count is 5,000,000. Thread1 needs to be designed so that every time it sees (counter -> value%100) == 0 it increments counter -> value by 100. That counts for 100 individual updates. You also need to keep track of how many times this happens and report it. Use the POSIX implementation of threads. Use getrusage to time the code.
You will need to look at the pthread create, pthread join and threads manual pages.
A tutorial and the man pages are here: http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
Information on trylock is here: http://man.yolinux.com/cgi-bin/man2html?cgi_command=pthread_mutex_lock
Write a C program to solve this problem.
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