Question
Analyze the following program and indicate what is true class Account { double balance; void withdraw(double amount) { balance -= amount; } void deposit(double amount)
Analyze the following program and indicate what is true
class Account {
double balance;
void withdraw(double amount)
{
balance -= amount;
}
void deposit(double amount)
{
balance += amount;
}
void transfer(Account from, Account to, double amount)
{
sync(from); sync(to);
from.withdraw(amount); to.deposit(amount);
release(to);
release(from); } }
a. should there be two threads which attempt to run transfer(a, b) and transfer(b, a) at the same time, then a deadlock is going to occur because the developer did not indicate the thread priority
b. should there be two threads which attempt to run transfer(a, b) and transfer(b, a) at the same time, then a deadlock is not going to occur because the developer correctly synchronized both from and to inside the method transfer
c. all answers are wrong
d. should there be two threads which attempt to run transfer(a, b) and transfer(b, a) at the same time, then a deadlock is going to occur because they try to acquire the resources in reverse order.
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