Hypothetical method lock over an object lock

Assignment Help C/C++ Programming
Reference no: EM13189609

Consider the following class de nition. This class is considered to be in an inconsistent state if the isConsistent() method returns false false false;

public class Foo {
long mVaLue;
long mVaLueTimesTwo;
/*a
• SETS THE STATE OF DUR OBJECT.

• PAUSES BRIEFLY BETWEEN SETTING THE FIRST AND SECOND
• VALUES IN ORDER TD INCREASE THE PROBABILITY THAT THE
• OBJECT WILL BE INTERROGATED WHILE IN AN INCONSISTENT
• STATE.

• OPARAM PVALUE THE VALUE TO UPDATE THE CURRENT STATE WITH,
public synchronised void set Values(long plIalue) { stfalue p Value ;
doPause(3);
mVaLueTimesTwo = pValue • 2;
}
/•:
• CHECKS TD SEE IF THE CURRENT STATE OF OUR OBJECT IS
• CONSISTENT.

• :RETURN TVS. 17 17 IS. * /
public synchronized boolean t sCons is t ent {
return (mVatue • 2 == mValueTimesTwo);
}
/**
• UTILITY ROUTINE - PAUSES OUR THREAD BY CALLING
• SLEEP AND SUPRESSING ANY INTERRUPTEDEXCEPTION.
* /
private static void doPause(lon$ pPause) { try {
Thread.steep(pPause);
} catch (InterruptedException e) { e.printStackTrace();
}
}

a. Imagine a hypothetical version of Java where the object lock is replaced by a method lock. Under this system a call to a synchronised method would assign a lock for that method to the calling thread. No other thread could then call this method because the lock is already allocated. However, other methods of the same object could still be called. Upon the method completing, the lock is released. Under this system, is it possible to put an instance of the Foo class into an inconsistant state? If so, give a code example which could create this situation and explain how it does so. If not, explain how the method lock prevents the possibility of inconsistent state.

b. Provide one possible motivation for choosing this hypothetical method lock over an object lock. Explain your answer.

Reference no: EM13189609

Questions Cloud

How much mix is needed to make each amount of lemonade : If q is the number of quarts of lemonade , then (1/4) q can be used to find the number of cups of lemonade mix needed to make the lemonade. How much mix is needed to make each amount of lemonade.
Use the gram-schmidt process to rewrite : Consider the basis B={(3,2),(1,-4)} for R^2, Use the Gram-Schmidt process to rewrite this basis as an orthonormalized basis.
Find the basis and dimension of the eigenspace : Find the basis and dimension of the eigenspace
Define the differential operation : Define the differential operation Dx: P^3 to P^2 such that Dx(p)=p' Determine a matrix A such that Dx(p)=Ap=p'
Hypothetical method lock over an object lock : Imagine a hypothetical version of Java where the object lock is replaced by a method lock. Under this system a call to a synchronised method would assign a lock for that method to the calling thread.
What percent of calories come from fat : You determine that 1 ounce of the peanut butter contains 115 calories and 9 grams of fat. What percent of calories come from fat?
Find the area of the trapezium : If the the two parellel sides of a trapezium is 11cm and 18cm .and the height is 10 cm. find the area of the trapezium.
What is the probability of a randomly selected student : If 309 students was enrolled in a weekend and evening program, or a regional center with 6,633 students what is the probability of a randomly selected student attended a regional center or the weekend and evening program?
How many cds does he have : Sam has a total of 58 DVD's and CD's. If the number of CD's is two more than three times the number of DVD's, how many CD's does he have?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a recursive definition in sml to reverse

Write a recursive definition in SML to reverse a list of elements and multiply all elements with 2.

  Program that will read in such an array

Write a program that will read in such an array, and repeatedly prints it so the user can select the direction in which to move next. The user's requested move can prompt a number of responses

  Program that takes a number between

Write a program that takes a number between -121 and 121 and output that number in the format of power of 3 (1,3,9,27)example:13 = 9+3+1

  Using opengl to create a cube

Write a program in C/C++ using OpenGL to create (without using built in function) a cube by implementing translation algorithm by translating along 1. X-axis, 2.Y-axis and 3. X and Y plane

  Computer programming techniques

Construct a program from a design and use appropriate functions

  A c++ program using the concept of function overloading

write a c++ program using the concept of function overloading for the following options : select the options from [1-3], 1- Area of rectangle 2- Area of square 3- Exit ,

  Main function to input twenty integers in given range

Write a main function to input 20 integers in range of 1-6, function should count number of times the numbers 2 and 5 occur. function must declare statics variables count2 and count5.

  Program to generate a star-based histogram for a quiz

Write a C++ program to generate a star-based histogram for a quiz (maximum score possible is 5) given to a class of N students, where N is an input from the user. Use arrays for computation.

  Use functional decomposition to solve

Use functional decomposition to solve this problem, and code the solution using functions wherever it makes sense to do so. Your program should check for invalid data such as nonpositive dimensions, number of rooms less than 1.

  Calculation the distance and time printed on the screen

After each calculation the distance and time printed on the screen and accumulated to the sum of the total distance and sum of the total time. The current destination should be saved as the old postion for the next calculation

  Write c++ program that reads in the average monthly rainfall

Write a C++ program that reads in the average monthly rainfall for a city for each month of the year and then reads in the actual monthly rainfall for each of the previous 12 months

  To use a sentinel loop so once the value of -99 i

modify this program to use a sentinal loop so once the value of -99 is entered after getting the pay and hours the program should end.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd