Question: 4 . A mutex is an exclusive lock to avoid non - atomic operation on a shared resource. Atomic operations are ensured by setting a

4. A mutex is an exclusive lock to avoid non-atomic 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 7 Lecture Note page 33 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 4
different inputs, including your student number and three larger integers than it. Provide
screenshots of your 4 tests/outputs.
4 . A mutex is an exclusive lock to avoid non -

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!