Question: 4 . A mutex is an exclusive lock to avoid non - atomic operation on a shared resource. Atomic operations are ensured by setting a
A mutex is an exclusive lock to avoid nonatomic operation on a shared resource. Atomic
operations are ensured by setting a mutex before using the resource and releasing it after using
the resource. Research the mutex and review the multithreaded program written in C language
on Week Lecture Note page Three Conceptual Pieces: Concurrency. Note that the lecture
code can be found on Moodle.
a Add a mutex in the code so that only one thread can access the variable counter at a
time and the final value of counter is always twice of the input. Assume the same header
files common.h and common threads.h are given, and only supply your modified code of
main.c with corresponding comments.
b Use either a locally installed compiler or an online compiler to test your code with
different inputs, including your student number and three larger integers than it Provide
screenshots of your testsoutputs
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
