answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vsevolod [243]
2 years ago
11

In Section 8.5.4, we described a situation in which we prevent deadlock by ensuring that all locks are acquired in a certain ord

er. However, we also point out that deadlock is possible in this situation if two threads simultaneously invoke the transaction () function. Fix the transaction () function to prevent deadlocks.
Computers and Technology
1 answer:
ruslelena [56]2 years ago
4 0

Answer:

See Explaination

Explanation:

Separating this critical section into two sections:

void transaction(Account from, Account to, double amount)

{

Semaphore lock1, lock2;

lock1 = getLock(from);

lock2 = getLock(to);

wait(lock1);

withdraw(from, amount);

signal(lock1);

wait(lock2);

deposit(to, amount);

signal(lock2);

}

will be the best solution in the real world, because separating this critical section doesn't lead to any unwanted state between them (that is, there will never be a situation, where there is more money withdrawn, than it is possible).

The simple solution to leave the critical section in one piece, is to ensure that lock order is the same in all transactions. In this case you can sort the locks and choose the smaller one for locking first.

You might be interested in
Determine the value of base x if (211)x = (6A)16
elena-14-01-66 [18.8K]
211x=6A•16
211x=96A
211x=96A
___. ___
211. 211

x=96A
___
211


It's hard to show fractions on here :•)
7 0
2 years ago
Read 2 more answers
After running the following pseudocode, what will the value of VARIABLE be? 1. Set value of VARIABLE to 5 2. Increase the value
Nutka1998 [239]

Answer:

10

Explanation:

you start with 5       5

you add 3                8

the variable is not odd so skip         8

the variable is even so add 1            9

the variable is odd so add 1              10

10

hope this helps <3

8 0
2 years ago
Given the dictionary, d, find the largest key in the dictionary and associate the corresponding value with the variable val_of_m
geniusboy [140]

Answer:

Here is the Python program:

d = {5:3, 4:1, 12:2}

val_of_max = d[max(d.keys())]

print(val_of_max)

Explanation:

The program works as follows:

So we have a dictionary named d which is not empty and has the following key-value pairs:

5:3

4:1

12:2

where 5 , 4 and 12 are the keys and 3, 1 and 2 are the values

As we can see that the largest key is 12. So in order to find the largest key we use max() method which returns the largest key in the dictionary and we also use keys() which returns a view object i.e. the key of dictionary. So

max(d.keys()) as a whole gives 12

Next d[max(d.keys())]  returns the corresponding value of this largest key. The corresponding value is 2 so this entire statement gives 2.

val_of_max = d[max(d.keys())] Thus this complete statement gives 2 and assigns to the val_of_max variable.

Next print(val_of_max) displays 2 on the output screen.

The screenshot of program along with its output is attached.

4 0
2 years ago
A type of printer is used to price model and shape is called
balandron [24]

Either a 3d,2d printer, or a price label gun

7 0
2 years ago
There are three seating categories at a stadium. Class A seats cost $20, Class B seats cost $15, and Class C seats cost $10. Wri
Westkost [7]

Answer:

Following are the program to this question:

def calculate_income(num,seat):#defining method calculate_income

   if seat=="A": #defining condition for seat a

       return num * 20 #return value

   if seat=="B": #defining condition for seat b

       return num * 15 #return value

   if seat=="C": #defining condition for seat c

       return num * 10 #return value

def show_income(a,b,c): #defining method show_Income

   sum=a+b+c # add total seats income

   print("Income for A class seats: $",a) #print value

   print("Income for B class seats: $",b) #print value

   print("Income for C class seats: $",c) #print value

   print("Total Income: $",sum) #print value

def main(): # defining main method

   a=int(input("Enter class A seats: ")) #input seats a value

   b=int(input("Enter class B seats: ")) #input seats b value

   c=int(input("Enter class C seats: ")) #input seats c value

   a_income=calculate_income(a,"A")  #call method for seat a

   b_income=calculate_income(b,"B") #call method for seat b

   c_income=calculate_income(c,"C") #call method for seat c

   show_income(a_income,b_income,c_income) # call method show_income for print all seat value

main()

Output:

Enter class A seats: 2

Enter class B seats: 3

Enter class C seats: 2

Income for A class seats: $ 40

Income for B class seats: $ 45

Income for C class seats: $ 20

Total Income: $ 105

Explanation:

The description of the above program can be described as follows:

  • In the above python program, three methods "calculate_income, show_income, and the main method" were defined.  
  • The method "calculate_income" accepts two-variable "num and seat" as the parameter, inside the method a three if block is used, that calculate all types of seat class rate and returns its value.
  • In the "show_income", we add all the seat value in the sum variable and use the print method, that prints all seat cost, and total cost.
  • In the main method, we input all seat value from user input and pass into the calculate_income method and collect all the return value, after calculating calculate_income we pass its return value into the show_income method, that prints all value.
5 0
2 years ago
Other questions:
  • Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline.
    11·2 answers
  • Drag the tiles to the correct boxes to complete the pairs.
    8·2 answers
  • Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following string
    7·1 answer
  • Write a program that asks the user to input an integer that is a perfect square. A perfect square is an integer that is equal to
    14·1 answer
  • Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). O
    5·1 answer
  • In evaluating the precedence rules used by Python, what statement is accurate? a. Addition and subtraction are evaluated after a
    8·2 answers
  • Question 1 :Which type of unshielded twisted pair (UTP) cable is commonly used for 1000BASE-T Ethernet networks and is often mad
    8·1 answer
  • To operate a vehicle in Florida, you must _____.
    9·2 answers
  • The vast amount of data collected from Internet searches, social media posts, customer transactions, military
    8·1 answer
  • How can we make our programs behave differently each time they are run?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!