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

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 Databases Questions!