Question

In: Computer Science

In formal terms, a monitor is an object which only allows one of its methods to...

In formal terms, a monitor is an object which only allows one of its methods to be executed at once.

For Java:

1) How could you implement a class satisfying the monitor’s fundamental mutual exclusion property – that is, a class whose instantiated objects ensured mutual exclusion among their methods? Provide a code fragment as an example.

2) Could you mutually exclude critical sections smaller than an entire method without resorting to mutex locks? If so, how?

3) How would you implement condition variables as we described them in class? Provide a code fragment as an example.

4) Does the implementation differ if you need more than one condition variable? If so, how?

Solutions

Expert Solution

Q1  implementing a class satisfying the monitor’s fundamental mutual exclusion property is by synchronized in java

we can write synchronized function

public synchronized void funcA(Object a ){

// code of the function

}

so if two thread access at same time only one thread will be able to execute it and other thread will wait

Q2 java also provide synchronized blocks

eg void funcA(object a)

{

synchronized(a){

// critical section of the code

}

}

Q3 to implement condition variable

public synchronized void func(object a)

{

// here we want to wait untill the value of any condition variable is false

whiile(isval == true)

{

a.wait();

}

}

in the above code our code will not execute and will be in waiting state untill the value of the variable isval is true;

Q4 the implementation will differ if there are multiple condition variable.

then there will be more condition which are to be checked in our code


Related Solutions

Which of the following methods of generating electricity is the only one that does NOT rely...
Which of the following methods of generating electricity is the only one that does NOT rely on Faraday's law of electromagnetic induction? A. Wind turbines B. Nuclear power plant C. A conventional fossil fuel power plant, burning coal, oil, or natural gas D. Solar photovoltaics (solar panels) E. Hydro-electric power plant
One of the methods physicists have used to search for magnetic monopoles is to monitor the...
One of the methods physicists have used to search for magnetic monopoles is to monitor the current produced in a loop of wire. Draw graphs of current in the loop vs. time for an electrically uncharged magnetic monopole passing through the loop, and for an electrically uncharged magnetic dipole (such as a neutron) passing through the loop with its north end head-first. Don’t worry too much about the details of the exact moment when the particle goes through the plane...
Choose an object and for that object list one qualitative variable and its subclass (Nominal, Ordinal)...
Choose an object and for that object list one qualitative variable and its subclass (Nominal, Ordinal) and from that very same object share one quantitative and its subclass (Discrete, Continuous). For each one of the two answers give an explanation for each one your examples. Do not use the following items: Computer Clothes Car Bear Cell phone users Finger nail file Pens Weights
Discount bond is a bond which after its original issue makes only one payment upon its...
Discount bond is a bond which after its original issue makes only one payment upon its maturity. This single payment accounts for repayment of principal (i.e., amount borrowed) plus interest. Consider discount bond G and discount bond C. Both G and C have the same face value and the same maturity. Bond G is a treasury bond and bond C is a corporate bond. All else equal a. The Present Value of G is less than the Present Value of...
Fiscal Policy is the means by which government adjusts its spending and tax rates to monitor...
Fiscal Policy is the means by which government adjusts its spending and tax rates to monitor and influence a nation's economy. It is the sister strategy to monetary policy and that is defined as a policy through which a central bank influences a nation's money supply. In my opinion I prefer a monetary policy because of its stability and fiscal relies too much on government debt. Fiscal policy decision making can also be influenced more on politics than the need...
Which of the following allows a sender to verify the source of a message? Select one:...
Which of the following allows a sender to verify the source of a message? Select one: a. Bitlocker b. Nonrepudiation c. Symmetric key d. Recovery key
Which one of the following was NOT a problem regarding utilitarian ethics? A) utilitarianism allows for...
Which one of the following was NOT a problem regarding utilitarian ethics? A) utilitarianism allows for slavery in rare cases where benefits outweigh costs B) if only consequences matter, it is permissible in some cases to punish the innocent C) if only consequences matter, it is permissible in some cases to break promises D) utilitarianism is a cold and calculating doctrine by trying to quantify social benefits According to the rule utilitarian, an act is morally right provided that: A)...
Suppose a manager has write permission only for the usmUserOwnAuthKeyChange column in usmUserTable, which allows change...
Suppose a manager has write permission only for the usmUserOwnAuthKeyChange column in usmUserTable, which allows change of only that manager’s password. However, the manager has full write access to the VACM tables. Explain how the manager can modify the local keys of other managers.
1. Which ONE of the following defendants is the only one in which a state court...
1. Which ONE of the following defendants is the only one in which a state court would absolutely be able to exercise in personam jurisdiction (without having to have additional information to make a determination)? a. An individual who is traveling through a state and allegedly causes damage while there. b.A business that is incorporated in somewhere in the United States. c. A business with manufacturing and distribution facilities located in multiple states throughout the country. d. An individual who...
An object is attached to a spring; which is attached to a wall. Describe its motion....
An object is attached to a spring; which is attached to a wall. Describe its motion. (max acceleration, max velocity).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT