Question

Two processes A and B are being executed concurrently, and they share several resources during execution,...

Two processes A and B are being executed concurrently, and they share several resources during execution, such as memory, processor time, and input output devices. Explain how the mutual exclusion approach can be used by A and B to avoid collision when both processes wish to use a certain shared resource

0 0
Add a comment Improve this question Transcribed image text
Answer #1

"Peterson's Algorithm"

  • "a simple algorithm that can be run by two processes to ensure mutual exclusion for one resource (say one variable or data structure)"
  • "does not require any special hardware"
  • "it uses busy waiting (a spinlock)"

Peterson's Algorithm
"Shared variables are created and initialized before either process starts. The shared variables flag[0] and flag[1] are initialized to FALSE because neither process is yet interested in the critical section. The shared variable turn is set to either 0 or 1 randomly (or it can always be set to say 0)."

var flag: array [0..1] of boolean;
turn: 0..1;
flag[k] means that process[k] is interested in the critical section
flag[0] := FALSE;
flag[1] := FALSE;
turn := random(0..1)

After initialization, each process, which is called process i in the code (the other process is process j), runs the following code:


repeat
flag[i] := TRUE;
turn := j;
while (flag[j] and turn=j) do no-op;
CRITICAL SECTION
flag[i] := FALSE;
REMAINDER SECTION
until FALSE;

Information common to both processes:
turn = 0
flag[0] = FALSE
flag[1] = FALSE

EXAMPLE 1

Process 0

Process 1

i = 0, j = 1

i = 1, j = 0

flag[0] := TRUE

turn := 1

check (flag[1] = TRUE and turn = 1)

-  Condition is false because flag[1] = FALSE

- Since condition is false, no waiting in while loop

-  Enter the critical section

-  Process 0 happens to lose the processor

flag[1] := TRUE

turn := 0

check (flag[0] = TRUE and turn = 0)

- Since condition is true, it keeps busy waiting until it loses the processor

- Process 0 resumes and continues until it finishes in the critical section

- Leave critical section

flag[0] := FALSE

- Start executing the remainder (anything else a process does besides using the critical section)

- Process 0 happens to lose the processor

check (flag[0] = TRUE and turn = 0)

- This condition fails because flag[0] = FALSE

- No more busy waiting

- Enter the critical section

EXAMPLE 2

Process 0

Process 1

i=0, j=1

i=1, j=0

flag[0] = TRUE

turn = 1

- Lose processor here

flag[1] := TRUE

turn := 0

check (flag[0] = TRUE and turn = 0)

- Condition is true so Process 1 busy waits until it loses the processor

check (flag[1] = TRUE and turn = 1)

-  This condition is false because turn = 0

- No waiting in loop

- Enters critical section

EXAMPLE 3

Process 0

Process 1

i=0, j=1

i=1, j=0

flag[0] = TRUE

- Lose processor here

flag[1] = TRUE

turn = 0

check (flag[0] = TRUE and turn = 0)

- Condition is true so, Process 1 busy waits until it loses the processor

turn := 1

check (flag[1] = TRUE and turn = 1)

- Condition is true so Process 0 busy waits until it loses the processor

check (flag[0] = TRUE and turn = 0)

- The condition is false so, Process 1 enters the critical section

Add a comment
Know the answer?
Add Answer to:
Two processes A and B are being executed concurrently, and they share several resources during execution,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION 1 . ______________ allow(s) a computer to invoke procedures that use resources on another computer...

    QUESTION 1 . ______________ allow(s) a computer to invoke procedures that use resources on another computer Pervasive computing Remote procedure calls (RPCs) Cloud computing Global computing QUESTION 2 The simplest example of a neural net is the: CPu perceptron systolic array supervised learning network QUESTION 3 The first company in the world to manufacture and sell what it identifies as a quantum computer is: D-Wave Computers Cray Google Intel QUESTION 4 A ______________ is a collection of distributed workstations that...

  • 1. Difference between sector sparing and sector slipping is A) sector sparing uses spare sectors while...

    1. Difference between sector sparing and sector slipping is A) sector sparing uses spare sectors while sector slipping does not. B) sector sparing results in copying of a single sector while sector slipping may result in copying of multiple sectors. C) sector sparing can help recover from hard errors while sector slipping cannot. D) sector slipping can help recover from hard errors while sector sparing cannot. 2. Which of the following is FALSE about swap space use? A) Swap space...

  • 10) Unlike a signal, which conveys only the occurrence of a particular event and contains no...

    10) Unlike a signal, which conveys only the occurrence of a particular event and contains no information content, a pipe can be thought of as a scratch file created by a system call. It can be used as a communications channel between concurrently running processes. The interface call to a pipe is similar to that for any file. In fact, the process reads and writes to a pipe just like any file. Unlike files, however, pipes do not represent actual...

  • Explain what enterprise resource planning (ERP) systems. Outline several of their key characteristics. Describe in reasonable...

    Explain what enterprise resource planning (ERP) systems. Outline several of their key characteristics. Describe in reasonable detail how a company leverages an ERP system and how its operations are improved after installing an ERP system like SAP. Explain how a supply chain management system helps an organization make its operations more efficient What is Upstream and Downstream management of the supply chain? Explain the concept of “Supply Network”, its benefits, and how technology made this concept available Explain the difference...

  • Chapter overview 1. Reasons for international trade Resources reasons Economic reasons Other reasons 2. Difference between...

    Chapter overview 1. Reasons for international trade Resources reasons Economic reasons Other reasons 2. Difference between international trade and domestic trade More complex context More difficult and risky Higher management skills required 3. Basic concept s relating to international trade Visible trade & invisible trade Favorable trade & unfavorable trade General trade system & special trade system Volume of international trade & quantum of international trade Commodity composition of international trade Geographical composition of international trade Degree / ratio of...

  • How did Samsung overtake Panasonic and Philips? What core competencies (resources and capabilities) did the firm...

    How did Samsung overtake Panasonic and Philips? What core competencies (resources and capabilities) did the firm possess that helped it to be successful? (Discuss the international strategy that Samsung executed.) Samsung Leadership Era: 2000–Present Samsung group was founded in 1938 by Byung-Chull Lee as a simple trading company in Taegu, Korea that exported basic goods such as dried fish, vegetables, and fruit before expanding into several business lines, including insurance, securities, and retail.43 In 1969, Lee decided to enter the...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

  • OPS Practice quiz 2. The benefits of risk pooling depend on the behavior of demand from...

    OPS Practice quiz 2. The benefits of risk pooling depend on the behavior of demand from one market relative to demand from another. True False 3. What is Supply Chain Management? A set of approaches utilized to efficiently integrate suppliers, manufacturers, warehouses and stores so that merchandize is produced, distributed at the right quantities, to the right locations and at the right time in order to minimize system wide costs while satisfying service level requirements. The management of the flow...

  • MANAGERIAL ACCOUNTING CASE STUDY.CASE ASSIGNMENT #1: Cortland Manufacturing, Inc.

    MANAGERIAL ACCOUNTING CASE STUDY.CASE ASSIGNMENT #1: Cortland Manufacturing, Inc.We constantly seem to be pricing ourselves out of some markets and not charging enough in others. Our pricing policy is pretty simple: we mark up our full manufacturing cost by 50%. That means a computer that costs us $2,000 to manufacture will sell for $3,000. Until now I thought this was a workable approach, but now I’m not so sure.Steve Works, CEO, Cortland Manufacturing, Inc. (CMI)Steve’s Controller, Sally Nomer, had just...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT