Consider the following multi-threaded C code. 1: void send money (acct * src, acct * dst, int amount) { 2: lock (& src -> mutex); 3: if (src -> value >= amount) { 4: src -> value -= amount; 5: lock (& dst -> mutex); 6: dst -> value += amount ; 7: unlock (& dst -> mutex); 8:} 9: unlock (& src -> mutex); 10: } 13 (a) Describe any bug(s) you see along with the line number. You need to justify your answer (b) Now revise the code to fix the bug. (if need to write the entire code with the change)

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section: Chapter Questions
Problem 7PP
icon
Related questions
Question

Can you please help me with question 2

Consider the following multi-threaded C code.
1: void send money (acct * src, acct * dst, int amount) {
2: lock (& src -> mutex);
3: if (src -> value >= amount) {
4: src -> value -= amount;
5: lock (& dst -> mutex);
6: dst -> value += amount ;
7: unlock (& dst -> mutex);
8:}
9: unlock (& src -> mutex);
10: }
13
(a) Describe any bug(s) you see along with the line number. You need to justify
your answer
(b) Now revise the code to fix the bug. (if need to write the entire code with the
change)
Transcribed Image Text:Consider the following multi-threaded C code. 1: void send money (acct * src, acct * dst, int amount) { 2: lock (& src -> mutex); 3: if (src -> value >= amount) { 4: src -> value -= amount; 5: lock (& dst -> mutex); 6: dst -> value += amount ; 7: unlock (& dst -> mutex); 8:} 9: unlock (& src -> mutex); 10: } 13 (a) Describe any bug(s) you see along with the line number. You need to justify your answer (b) Now revise the code to fix the bug. (if need to write the entire code with the change)
Expert Solution
steps

Step by step

Solved in 1 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr