Concurrent access to objects

Assignment Help JAVA Programming
Reference no: EM13963564

Concurrent Access to Objects

This question asks about synchronizing methods for stack and queue objects.

(a) Bounded stacks can be de?ned as objects, each containing an array of up to n items. Here is apseudocode for one form of stack class.

class Stack private
contents : array[1..n] of int top : int
constructor
stack () = top := 0 public
push (x:int) : unit = if top <> then
top := top + 1; contents[top] := x
else raise stack full; pop ( ) : int =
if top > 0 then top := top - 1:
return contents[top+1] else raise stack empty;
end Stack

If stacks are going to be used in a concurrent programming language, what problem might occur if two threads invoke push and pop simultaneously? Explain.

(b) How would you solve this problem by using Java concurrency concepts? Explain.

(c) Suppose that, instead of stacks, we have queues:

class Queue private
contents : array[1..n] of int front, back : int
constructor
queue() = front := back := 1 public
insert (x:int) : unit =
if back+1 mod n != front then back := back+1 mod n; contents[back] := x
else raise queue full; remove ( ) : int =
if front != back then front := front+1 mod n; return contents[front]
else raise queue empty;
end Queue

Suppose that ?ve elements have been inserted into a queue object and none of them have been removed. Do we have the same concurrency problem as we did with push and pop when one thread invokes insert and another thread simultaneously invokes remove? Assume that n is 10. Explain.

Reference no: EM13963564

Questions Cloud

Explain the time-dependence of the ground state wavefunction : Determine the specific solutions inside the well for the ground state and for the rst excited state by applying the boundary conditions at x = 0 and at x = L. Now consider a 50:50 superposition of the ground state and the rst excited state.
A stock will have quarterly dividends of $0.78 : A stock will have quarterly dividends of $0.78, $0.83, $0.76, $0.92, $0.98, $13, $36, $38 and then grow by 0.02 a year, compounded quarterly. If the required return is 0.07 per year compounded quarterly, what should the price be?
Determine the amount and direction of heat interactions : The heat engine in the atachment operates reversibly and draws 1200 KJ of heat from the 200 K reservoir
Prepare a classified statement of financial position : Prepare a classified statement of financial position. Assume that $15,000 of the notes payable will be paid in 2018
Concurrent access to objects : This question asks about synchronizing methods for stack and queue objects. (a) Bounded stacks can be de?ned as objects, each containing an array of up to n items. Here is apseudocode for one form of stack class.
Compounded annually, : A stock will have annual dividends of $0.65, $0.8, $0.78, $0.76, $0.82, and then grow by 0.02 a year. If the required return is 0.16 per year compounded annually, what should the price be?
Calculate the energy of the gas : There has recently been considerable interest in one-dimensional electrical conductors. In this problem, you are asked to calculate some free-electron properties for a system of length L containing N electrons. Thus, there are n =N/L electrons per..
Actual overhead costs for the year : Pinnacle Corp. budgeted $700,000 of overhead cost for the current year. Actual overhead costs for the year were $650,000. Pinnacle’s plant wide allocation base, machine hours, was budgeted at 100,000 hours
Write a brief report that identify surgical operations : To analyse a set of data (in Microsoft Excel), and write a brief report (in Microsoft Word), identifying and explaining your insights into the surgical operations of BestHealth Hospital.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a recursive method to print all permutations of string

Write a recursive method to print all the permutations of a string. For instance, for a string abc, the printout is: abc acb bac bca cab cba

  Create a calculator function

This is the code for my trip planner,you need to figure out how to create a calculator function to enable users to calculate their own costs if they choose

  Function that finds the smallest item in an arraybag

Write me a function that finds the smallest item in an ArrayBag (by reference) and returns true if the arrayBag is not empty and false otherwise.

  Create a two dimensional integer array in java

Create a two dimensional integer array in JAVA that produces the sum of rows and columns as selected by the user.

  Java program that prompts for the gpa

This assignment will give you practice with interactive programs, if/else statements and methods that return values. Your program will prompt the user for information about two applicants and compute an overall score for each applicant. This is ..

  Write a java application using netbeans ide

Write a Java application using NetBeans Integrated Development Environment (IDE) or jGROUP IDE that calculates the total annual compensation of a salesperson

  Design and implement a java version of the game memory

Design and implement a Java version of the game Memory

  Java program to print strings given at command line

Write down program Average.java to print strings which it is given at command line, one per line. If nothing is given at command line, then print "No arguments".

  Create a panel with borderlayout

Create a panel with BorderLayout. Add a button labeled "OK" to the south side of the panel - given the program, show the values of the array

  Declare a linkedlist that stores strings

Include a text file showing the output from at least 3 future value calculations

  Calculates the total annual compensation of a salesperson

Write a Java application using NetBeans Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors: A salesperson will earn a fixed salary of $35,750

  You have in your program an arraylist which contains

you have in your program an arraylist that contains employee salaries double type in arbitrary order. you need to

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