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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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