Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Operating System Expert

As we already know, threadsmust ensure consistency; otherwise, race conditions (non-deterministic results) might happen. Now consider the "too much milk problem": two people share the same fridge and must guaran tee that there's always milk, but not too much milk. How can we solve it? First, we consider some important concepts and their de?nitions:

 Mutex: prevents things from operating on the same data at the same time;

 Critical section: a piece of code that only one thread can execute at a time;

 Lock: a mechanism for mutual exclusion; the program locks on entering a critical section, accesses the shared data, and then unlocks. Also, a program waits if it tries to enter a locked section.

 Invariant: something that must always be true when not holding the lock. For the above mentioned problem, we want to ensure some correctness properties. First, we want to guarantee that only one person buys milk when it is need (this is the safety property, aka "noth-ing bad happens"). Also, wewant to ensure that someone does buymilkwhen needed (the progress property, aka "something good eventually happens"). Nowconsider thatwe can use the following atomic operations when writing the code for the problem:

 "leave a note" (equivalent to a lock)

 "remove a note" (equivalent to an unlock)


"don't buy milk if there's a note" (equivalent to a wait)

An atomic operation is an unbreakable operation. Once it has started, no other thread or process can interrupt it until it has ?nished. Our ?rst try could be to use the following code on both threads:

if (no milk && no note) {
leave note;
buy milk;
remove note;
}
Unfortunately, this doesn't work because both threads could simultaneously verify that there's no note and no milk, and then both would simultaneously leave a note, and buy more milk. The problem in this case is that we end up with too much milk (safety property not met).

Now consider our solution #2:

Thread A:
leave note "A";
if (no note "B")
if (no milk)
buy milk;
remove note "A";
Thread B:
leave note "B";
if (no note "A");
if (no milk)
buy milk;
remove note "B";

The problemnowis that if both threads leave notes at the same time, neitherwill ever do anything. Then, we end up with no milk at all, which means that the progress property not met. Now, let's consider an approach that does work:

Thread A
leave note A
while (note B)
do nothing
if (no milk)
buy milk
remove note A
Thread B
leave note B;
if (no note A)
if (no milk)
buy milk;
remove note B;

This approach, unlike the two examples considered on the previous class, does work. However, it is complicated: it is not quick-and-easy to convince yourself that these two sections of code always produce the desired behavior.

Operating System, Computer Science

  • Category:- Operating System
  • Reference No.:- M9527885

Have any Question?


Related Questions in Operating System

Show all stepssuppose that the following processes arrive

Show all steps Suppose that the following processes arrive for execution at the times indicated. Each process will run the listed amount of time. in answering the questions, use non-preemptive scheduling and base all dec ...

Question state the required answer precisely and then

Question : State the required answer precisely and then provide proper explanation. It is not enough to provide one- word or one-line answers. What is the purpose of the command interpreter? Why is it usually separate fr ...

Catalog course descriptionin this course students carry out

Catalog Course Description In this course students carry out independent research in a significant technical area of information, network, and computer security. The student is to investigate a technical area, research i ...

Question you are a security administrator responsible for

Question: You are a security administrator responsible for providing secure configuration requirements for new laptop deployments. After reading Module 2 of Certified Secure Computer User v2exercises, apply the configura ...

Question description of lasa in this assignment you will

Question: Description of LASA: In this assignment, you will select a real-world operating system (can be for a PC, server, tablet, handheld, or embedded device). You will introduce the operating system and its components ...

Question research hex editors available for mac os and

Question : Research hex editors available for Mac OS and Linux. Based on the documentation, how easy would validating these tools be? Select at least two hex editors for each OS, and discuss what you would do to validate ...

State the required answer precisely and then provide proper

State the required answer precisely and then provide proper explanation. It is not enough to provide one- word or one-line answers. Briefly describe the following concepts and indicate how they are related in the context ...

Question 1answer the following questions 10 marks a

Question 1 Answer the following questions: 10 marks a. Consider the following page reference string: 3, 1, 4, 1, 2, 3, 5, 3, 2, 1, 2,5, 4, 3, 5, 2, 4,2, 5,3 Using the above page reference string display the contents of t ...

Assignment -building a multi-threaded web server using c

Assignment - Building a multi-threaded web server using C and p threads, following the model from the lecture. Your program will have one thread acting as a dispatcher thread, listening fornetwork connections with reques ...

Question what do you see as the major differences between

Question : What do you see as the major differences between UNIX/Linux and other operating systems, such as Windows and Mac OS X? The response must be typed, single spaced, must be in times new roman font (size 12) and m ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As