To view this presentation, you'll need to enable Flash.

Show me how

After you enable Flash, refresh this webpage and the presentation should play.

Loading...

PPT – Mutual Exclusion Using Atomic Registers PowerPoint presentation | free to download - id: 3c1bc-NzA2Y

The Adobe Flash plugin is needed to view this content

View by Category

Presentations

Products
Sold on our sister site CrystalGraphics.com

About This Presentation

Write a Comment

User Comments (0)

Transcript and Presenter's Notes

Mutual Exclusion Using Atomic Registers

Lecturer Netanel Dahan Instructor Prof. Yehuda

Afek

B.Sc. Seminar on Distributed Computation Tel-Aviv

University 11.03.07

Based on the book Synchronization Algorithms and

Concurrent Programming by Gadi Taubenfeld

Overview

- Introduction.
- Algorithms for two processes Petersons and

Kessels algorithms. - Tournament algorithms.
- Lamports fast algorithm.
- Starvation free algorithms the bakery algorithm

and the black-white bakery version. - Tight space bounds lower and upper bounds of

shared resources.

- Introduction

The Mutual Exclusion Problem

The mutual exclusion problem is the guarantee of

mutually exclusive access to a shared resource,

or resources when there are several competing

processes. A situation as described above, where

several processes may access the same resource

and the final result depends on who runs when, is

called a race condition, and the problem is

essentially avoiding such conditions. The problem

was first introduced by Edsgar W. Dijkstra in

1965.

General Solution

In order to solve the problem, we add the entry

and exit code, in a way which guarantees that the

mutual exclusion and deadlock freedom properties

are satisfied.

remainder code

Surprise, surprise the rest of the code.

entry code

The part of the code in which the shared

resources reside.

critical section

exit code

Assumptions

- The remainder code may not influence other

processes. - Shared objects appearing in the entry or exit

code may not be referred to in the remainder or

critical section. - A process can not fail when not in the remainder.
- Once a process starts executing the CS and exit

code, it always finishes them.

Related Concepts

- Mutual Exclusion No two processes are in their

critical section at the same time. - Deadlock Freedom If a process is trying to

enter its critical section, then some process,

not necessarily the same one, will eventually

enter the critical section. - Starvation Freedom If a process is trying to

enter its critical section, eventually it will

succeed.

Algorithms for two processes

Algorithms for two processes

We start with describing two algorithms that

solve the mutual exclusion problem for two

processes. They will be used for introducing the

problem and possible solutions using atomic

registers. Throughout the presentation, it shall

be known that the only atomic operations on

shared registers are reads and writes. In

addition, we will use the statement await

condition as an abbreviation for while !condition

do skip.

Petersons Algorithm

- Developed by Gary L. Peterson in 1981.
- The algorithm makes use of a register called

turn, which can take the values 0 and 1, the

identifiers for the two possible processes, and

two boolean registers b0 and b1. - Both processes can read and write to turn, read

b0 and b1, but only process i can write to

bi .

Petersons Algorithm

Initially b0 b1 false, turn is

immaterial.

- Process 1
- b1 true
- turn 1
- await (b0 false or turn 0)
- critical section
- b1 false

- Process 0
- b0 true
- turn 0
- await (b1 false or turn 1)
- critical section
- b0 false

Petersons Algorithm

Check if there is contention. If not, I can go in

the CS. Else

Check if I crossed the barrier first. If so I can

go in the CS, else I have to wait.

- Process i
- bi true
- turn i
- await (b1-i false or turn 1-i)
- critical section
- bi false

Indicate I am in contention for the critical

section.

Cross the turn barrier and indicate the crossing

for later observation.

Do my thang

Indicate I am not contending anymore.

Properties

- Satisfies mutual exclusion and starvation

freedom. - Contention-free time complexity is four accesses

to the shared memory. - Process time complexity is unbounded.
- Three shared registers are used.

Kessels single-writer algorithm

- A variation of petersons algorithm which uses

single-writer registers. - Uses 2 registers, which can take the values 0 and

1, and 2 boolean registers. - Developed by J. L. W. Kessels in 1982.

Kessels single-writer algorithm

Initially b0 b1 false, turn0 and

turn1 are immaterial. Only process i can write

to bi and turni. locali is local for

process i.

- Process 1
- b1 true
- local1 1 - turn0
- turn1 local1
- await (b0 false or local1 turn0)
- critical section
- b1 false

- Process 0
- b0 true
- local0 turn1
- turn0 local0
- await (b1 false or local0 ? turn1)
- critical section
- b0 false

Properties

- Same as Petersons algorithm, besides the use of

4 shared registers. - In addition, satisfies local spinning.

?

Local Spinning

- Accessing a physically remote register is costly.
- When a process waits, using an await statement,

it does so by spinning (busy-waiting) on

registers. - It is much more efficient to spin on a

locally-accessible registers.

Kessels single-writer algorithm

Initially b0 b1 false, turn0 and

turn1 are immaterial. Only process i can write

to turni. locali is local for process i.

- Process 1
- b1 true
- local1 1 - turn0
- turn1 local1
- await (b0 false or local1 turn0)
- critical section
- b1 false

- Process 0
- b0 true
- local0 turn1
- turn0 local0
- await (b1 false or local0 ? turn1)
- critical section
- b0 false

Tournament Algorithms

Tournament Algorithms

- A generalization method which enables the

construction of an algorithm for n processes from

any given solution for 2 processes. - Developed by Gary L. Peterson and Michael J.

Fischer in 1977.

Tournament Algorithms

Tournament Algorithms

- An important side affect is that a process may

enter the critical section an arbitrary number of

times before some other process in a different

subtree.

Lamports Fast Algorithm

Lamports Fast algorithm

- An algorithm for n processes.
- Provides fast access to the critical section in

the absence of contention. - Uses 2 registers which are long enough to store a

process identifier, and a boolean registers

array. - Developed in 1987 by Lamport.

Lamports Fast algorithm

- Process is program
- start bi true
- x i
- if y ? 0 then bi false
- await y 0
- goto start fi
- y i
- if x ? i then bi false
- for j 1 to n do

await !bj od - if y ? i then await y

0 - goto

start fi fi - critical section
- y 0
- bi false

Indicate contending bi true

Contention? y ? 0 ?

yes

Wait until CS is released

no

The last to cross the barrier!

Barrier y i

Continue only after it is guaranteed that no

one can cross the barrier

Contention? x ? i ?

yes

no

Last to cross the barrier? y i ?

yes

critical section

no

exit code

Wait until CS is released

Properties

- Satisfies mutual exclusion and deadlock freedom.
- Starvation of individual processes is possible.
- Fast access In the absence of contention, only 7

accesses to the shared memory are required. - Process time complexity is unbounded.
- n 2 shared registers are used.

Starvation Free Algorithms

Starvation Free Algorithms

- In many practical systems, since contention is

rare deadlock freedom is a sufficient property. - For other systems, it might be a too weak

requirement, such as in cases where a process

stays a long time in the critical section.

The Bakery Algorithm

- Based on the same policy as in a bakery, where

each customer gets a number which is larger then

the numbers waiting in line, and the lowest

number holder gets served. - Assumed to be up to n processes contending to

enter the CS. - Each process is identified by a unique number

from 1n.

The Bakery Algorithm

- The algorithm makes use of a boolean array

choosing1n and an integer array number1n.

Entries choosingi and numberi can be read by

all processes but written only by process i. - The relation lt, is used on pairs of integers and

is called the lexicographic order relation. It is

defined by (a, b) lt (c, d) if a lt c or if a

c and b lt d.

The Bakery Algorithm

- Initially all entries in number and choosing are

0 and false respectively. - process is program
- chossing i true
- number i 1 maximum(number1,,numbern)

- choosing i false
- for j 1 to n do
- await choosing j false
- await (number j 0 or (number i

, i) lt (number j , j)) - od
- critical section
- number i 0

Properties

- Satisfies mutual exclusion and first-come-first-se

rved. - The algorithm is not fast even in the absence of

contention a process is required to access the

shared memory 3(n-1) times.

Properties

- Uses 2n shared registers.
- Non-atomic registers it is enough to assume that

the registers are safe, meaning that writes which

are concurrent with reads will return an

arbitrary value. - The size of numberi is unbounded.

The Bakery Algorithm

The Black-White Bakery Algorithm

- A variant of the bakery algorithm developed by

Gadi Taubenfeld in 2004. - By using a single additional shared bit the

amount of space required is bounded. - The shared bit represents a color for the

customers tickets, while the idea is that there

is a priority to the holders of a ticket which

color is different then the shared bit.

The Black-White Bakery Algorithm

Tight Space Bounds

Tight Space Bounds

- We show that for n processes, n shared
- bits are necessary and sufficient for
- solving the mutual exclusion problem
- assuming the only atomic operations are
- reads and writes, and the processes are
- asynchronous.

A Lower Bound

- Any deadlock free mutual exclusion algorithm for

n processes must use at least n shared registers. - Proved by James E. Burns and Nancy A. Lynch in

1980.

Definitions

- Event an action carried by a specific process.
- x, y and z will denote runs.
- When x is a prefix of y, (y x) denotes the

suffix of y obtained by removing x.

Definitions

- x y is an extension of x by y.
- We always know where (remainder, entry, CS, exit)

a process is. - If a run involves only process p, then all events

in the run involve only process p.

Definitions

- Run x looks like run y to process p.
- Process p is hidden in run x.
- Process p covers register r in run x.

Illustrations

- Run x looks like run y to process p.

- run x
- p reads 5 from r1
- q writes 6 to r1
- p writes 7 to r1
- q writes 8 to r1
- p reads 8 from r1

- run y
- p reads 5 from r1
- p writes 7 to r1
- q writes 6 to r1
- q reads 6 from r1
- q writes 8 to r1
- p reads 8 from r1

- q writes 6 to r1

Illustrations

- Process p is hidden in run x.

- p reads 5 from r1
- q reads 5 from r1
- p writes 7 to r1
- q writes 8 to r1
- p reads 8 from r1
- q writes 6 to r1

Illustrations

- Process p covers register r in run x.

p covers r1 at this point

- p writes 7 to r1
- q writes 8 to r1
- p reads 8 from r1
- p writes 2 to r1

Lemma 1

- Let x be a run which looks like run y to every

process in a set P. if z is an extension of x

which involves only processes in P then y (z

x) is a run.

x

y

P events only

then, this is also a run

z

Lemma 2

- If a process p is in its CS in run z, then p is

not hidden in z.

p is in its critical section

then, p is not hidden

z

Lemma 3

- Let x be a run in which all the processes are

hidden. Then, for any process p, there exists a

run y which looks like x to p, where all

processes except maybe p are in their remainders. - Proof by induction on the number of steps of

processes other then p.

Lemma 4

- Let x be a run where all the processes are

hidden. Then, for any process p, there is an

extension z of x which involves only p in which

p covers some register that is not covered by any

other process.

Proof

- From lemma 3, there exists a run y which looks

like x to p, where all processes except maybe p

are in their remainders. By the deadlock freedom

property, starting from y process p is able to

enter the CS on its own.

Proof

- By lemma 1, since y looks like x to p, p

should be able to do the same starting from x. - Suppose p only writes registers covered by other

processes before entering the CS.

Proof

- Then, when all covered registers are written one

after the other we get a run in which p is hidden

and is in its CS. - By lemma 2, this is not possible.

Main Lemma

- Let x be a run in which all the processes are in

their remainders. Then, for every set of

processes P there is an extension z of x which

involves only processes in P, in which the

processes in P are hidden and cover P distinct

registers. - Proof by induction on the size of P.

An Upper Bound

- There is a deadlock free mutual exclusion

algorithm for n processes which uses n shared

bits. - As a prove we will see the One-Bit Algorithm

developed independently by J. E. Burns (1981) and

L. Lamport (1986).

The One-Bit Algorithm

- Up to n processes may be contending to enter the

CS, each with a unique identifier from 1n. - Uses a boolean array b, where all processes can

read all entries, but only process i can write

bi.

The One-Bit Algorithm

- Initially all entries in b are false.
- Process is program
- repeat
- bi true j 1
- while (bi true) and (j lt i) do
- if bj true then bi false await

bj false fi - j j 1
- od
- until bi true
- for j i 1 to n do await bj false od
- critical section
- bi false

Properties

- Satisfies mutual exclusion and deadlock freedom.
- Starvation of individual processes is possible.
- Not fast even in the absence of contention a

process needs to access all of the n shared bits.

Properties

- Not symmetrical a process with a smaller

identifier has higher priority. - Uses only n shared bits, hence it is space

optimal . - Non-atomic registers it is enough to assume that

the registers are safe, meaning that writes which

are concurrent with reads will return an

arbitrary value.

Questions

- ?

Thank you for listening

About PowerShow.com

PowerShow.com is a leading presentation/slideshow sharing website. Whether your application is business, how-to, education, medicine, school, church, sales, marketing, online training or just for fun, PowerShow.com is a great resource. And, best of all, most of its cool features are free and easy to use.

You can use PowerShow.com to find and download example online PowerPoint ppt presentations on just about any topic you can imagine so you can learn how to improve your own slides and presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

You can use PowerShow.com to find and download example online PowerPoint ppt presentations on just about any topic you can imagine so you can learn how to improve your own slides and presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

Recommended

«

/ »

Page of

«

/ »

Promoted Presentations

Related Presentations

Page of

Home About Us Terms and Conditions Privacy Policy Presentation Removal Request Contact Us Send Us Feedback

Copyright 2018 CrystalGraphics, Inc. — All rights Reserved. PowerShow.com is a trademark of CrystalGraphics, Inc.

Copyright 2018 CrystalGraphics, Inc. — All rights Reserved. PowerShow.com is a trademark of CrystalGraphics, Inc.

The PowerPoint PPT presentation: "Mutual Exclusion Using Atomic Registers" is the property of its rightful owner.

Do you have PowerPoint slides to share? If so, share your PPT presentation slides online with PowerShow.com. It's FREE!