Question: Problem Description: The purpose of this create a multithreaded program that uses mutex to protect critical code sections. 1 . Your C code will manage
Problem Description: The purpose of this create a multithreaded program that uses mutex to protect critical code sections.
Your C code will manage one person bank account, and its ATM withdrawal.
The program will threads, then will attempt withdraws in parallel.
The withdraw function calls the following functions in sequence:
a Debit: this simulates the operation of deducting the withdrawn amount from the person account
b Dispense: This simulates dispensing the cash
c Receipt: This simulates printing an summary receipt of the operation
void debitlong tid, long amount accountbalanceamount; printfIn thread ld: Debiting ld dollars, balance after: ld
tid, amount, accountbalance;
void dispense long tid, long amount printfIn thread ld: dispensing ld dollars from ATM
tid, amount;
void receiptlong tid, long amount printfIn thread ld: Receipt: Balance before: ldAmount withdrawn: ldBalance after: ld
tid, accountbalanceamount, amount, accountbalance;
void withdrawvoid threadid long tid longthreadid; debittidtid; dispensetidtid; receipttidtid;
Without treating the functions described above as a critical code section, verify that you will be getting some abnormal results.
Now, protect all the code inside the withdraw method with a mutex variable, and notice the execution output difference.
Submit your code including the mutex protected withdraw. Follow class coding and submission guidelines
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
