Avoiding Register Overflow in the Bakery Algorithm Amirhossein - - PowerPoint PPT Presentation

avoiding register overflow in the bakery algorithm
SMART_READER_LITE
LIVE PREVIEW

Avoiding Register Overflow in the Bakery Algorithm Amirhossein - - PowerPoint PPT Presentation

Avoiding Register Overflow in the Bakery Algorithm Amirhossein Sayyadabdi Mohsen Sharifi University of Isfahan University of Science and Technology ahsa@eng.ui.ac.ir msharifi@iust.ac.ir SRMPDS 20, Edmonton, AB, Canada Avoiding Register


slide-1
SLIDE 1

Avoiding Register Overflow in the Bakery Algorithm

Amirhossein Sayyadabdi University of Isfahan ahsa@eng.ui.ac.ir Mohsen Sharifi University of Science and Technology msharifi@iust.ac.ir

SRMPDS ‘20, Edmonton, AB, Canada

slide-2
SLIDE 2

Agenda

  • Background on mutual exclusion and the Bakery algorithm
  • Problem statement
  • Bakery++
  • Performance, practicality and correctness of Bakery++
  • Discussion and future work
  • Conclusions

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 1 /15

slide-3
SLIDE 3

Mutual Exclusion

Started the field of concurrency.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 1 /15

slide-4
SLIDE 4

Mutual Exclusion

Started the field of concurrency. Originally proposed and solved by Dijkstra in 1965.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 1 /15

slide-5
SLIDE 5

Mutual Exclusion

Started the field of concurrency. Originally proposed and solved by Dijkstra in 1965. A group of independent sequential processes that have access to shared memory.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 1 /15

slide-6
SLIDE 6

Mutual Exclusion

Started the field of concurrency. Originally proposed and solved by Dijkstra in 1965. A group of independent sequential processes that have access to shared memory. Prevent the processes from executing a specific region of code called the “critical section” simultaneously.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 1 /15

slide-7
SLIDE 7

Mutual Exclusion (cont.)

Correctness conditions as specified by Knuth: 1. No two processes are allowed to execute their critical sections simultaneously.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 2 /15

slide-8
SLIDE 8

Mutual Exclusion (cont.)

Correctness conditions as specified by Knuth: 1. No two processes are allowed to execute their critical sections simultaneously. 2. A reliable process should be allowed to enter its critical section eventually.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 2 /15

slide-9
SLIDE 9

Mutual Exclusion (cont.)

Correctness conditions as specified by Knuth: 1. No two processes are allowed to execute their critical sections simultaneously. 2. A reliable process should be allowed to enter its critical section eventually. 3. Crashing of a process should not block others from accessing the critical section.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 2 /15

slide-10
SLIDE 10

Mutual Exclusion (cont.)

Correctness conditions as specified by Knuth: 1. No two processes are allowed to execute their critical sections simultaneously. 2. A reliable process should be allowed to enter its critical section eventually. 3. Crashing of a process should not block others from accessing the critical section. 4. Processes may fail at any time and then restart outside of the critical section.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 2 /15

slide-11
SLIDE 11

Mutual Exclusion (cont.)

Correctness conditions as specified by Knuth: 1. No two processes are allowed to execute their critical sections simultaneously. 2. A reliable process should be allowed to enter its critical section eventually. 3. Crashing of a process should not block others from accessing the critical section. 4. Processes may fail at any time and then restart outside of the critical section. 5. No assumptions are made about the execution speeds of processes.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 2 /15

slide-12
SLIDE 12

Resource Management

Resource management concerns the coordination and collaboration of users.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 3 /15

slide-13
SLIDE 13

Resource Management

Resource management concerns the coordination and collaboration of users. It is usually based on making a decision.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 3 /15

slide-14
SLIDE 14

Resource Management

Resource management concerns the coordination and collaboration of users. It is usually based on making a decision. In the case of mutual exclusion, that decision is about granting access to a resource.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 3 /15

slide-15
SLIDE 15

Resource Management

Resource management concerns the coordination and collaboration of users. It is usually based on making a decision. In the case of mutual exclusion, that decision is about granting access to a resource. Mutual exclusion is useful for supporting resource access management.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 3 /15

slide-16
SLIDE 16

The Bakery Algorithm

1. Processes can enter their critical sections in first-come-first-served order.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 4 /15

slide-17
SLIDE 17

The Bakery Algorithm

1. Processes can enter their critical sections in first-come-first-served order. 2. The failure of individual system components will not cause the entire system to halt.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 4 /15

slide-18
SLIDE 18

The Bakery Algorithm

1. Processes can enter their critical sections in first-come-first-served order. 2. The failure of individual system components will not cause the entire system to halt. 3. No process writes into the memory of other processes.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 4 /15

slide-19
SLIDE 19

The Bakery Algorithm

1. Processes can enter their critical sections in first-come-first-served order. 2. The failure of individual system components will not cause the entire system to halt. 3. No process writes into the memory of other processes. 4. If a read and a write occur simultaneously at a memory location, then the value

  • btained by the read operation may have any arbitrary value.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 4 /15

slide-20
SLIDE 20

integer array choosing [1..N], number [1..N]; begin integer j; L1: choosing[i] := 1; number[i] := 1 + maximum (number[1], … , number[N]); choosing[i] := 0; for j = 1 step 1 until N do begin L2: if choosing[j] ≠ 0 then goto L2; L3: if number[j] ≠ 0 and (number[j], j < number[i], i) then goto L3; end; critical section; number[i] := 0; noncritical section; goto L1; end

The Bakery Algorithm (cont.)

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 5 /15

slide-21
SLIDE 21

Trouble with Bakery

The Bakery algorithm assumes unbounded registers.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 6 /15

slide-22
SLIDE 22

Trouble with Bakery

The Bakery algorithm assumes unbounded registers. The value of number[i] for process i may tend to infinity!

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 6 /15

slide-23
SLIDE 23

Trouble with Bakery

The Bakery algorithm assumes unbounded registers. The value of number[i] for process i may tend to infinity! Two competing processes may keep incrementing this value forever: number[i] := 1 + maximum (number[1], … , number[N]);

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 6 /15

slide-24
SLIDE 24

Trouble with Bakery

The Bakery algorithm assumes unbounded registers. The value of number[i] for process i may tend to infinity! Two competing processes may keep incrementing this value forever: number[i] := 1 + maximum (number[1], … , number[N]); This causes register overflow in real systems.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 6 /15

slide-25
SLIDE 25

Our Purpose

Avoid register overflows in the Bakery algorithm without making compromises. Previous approaches to achieve the same goal:

  • Introduce new shared variables.
  • Redefine certain operations or functions in the algorithm.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 7 /15

slide-26
SLIDE 26

Notable Solutions

The majority of approaches to avoid overflows in the Bakery algorithm include: 1. Changing the definitions of “<” operator and “maximum” function.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 8 /15

slide-27
SLIDE 27

Notable Solutions

The majority of approaches to avoid overflows in the Bakery algorithm include: 1. Changing the definitions of “<” operator and “maximum” function. 2. Using modulo arithmetic instead of integer arithmetic.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 8 /15

slide-28
SLIDE 28

Notable Solutions

The majority of approaches to avoid overflows in the Bakery algorithm include: 1. Changing the definitions of “<” operator and “maximum” function. 2. Using modulo arithmetic instead of integer arithmetic. 3. Introducing new shared variables or using extra memory.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 8 /15

slide-29
SLIDE 29

Notable Solutions

The majority of approaches to avoid overflows in the Bakery algorithm include: 1. Changing the definitions of “<” operator and “maximum” function. 2. Using modulo arithmetic instead of integer arithmetic. 3. Introducing new shared variables or using extra memory. 4. Resetting the values of registers before an overflow occurs.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 8 /15

slide-30
SLIDE 30

The Bakery++ Algorithm

There is an important theoretical question in the paper that introduced Bakery: “Can one find an algorithm for finite processors such that processors enter their critical sections on a first-come-first-served basis, and no processor may write into another processor’s memory?”

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 9 /15

slide-31
SLIDE 31

The Bakery++ Algorithm

There is an important theoretical question in the paper that introduced Bakery: “Can one find an algorithm for finite processors such that processors enter their critical sections on a first-come-first-served basis, and no processor may write into another processor’s memory?” To our knowledge, all of the previous works on bounding the Bakery algorithm have failed to answer this question.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 9 /15

slide-32
SLIDE 32

Bakery++

Bakery++ is a slightly modified version of the Bakery algorithm.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 10 /15

slide-33
SLIDE 33

Bakery++

Bakery++ is a slightly modified version of the Bakery algorithm. We call it “Bakery++” because it is almost identical to Bakery.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 10 /15

slide-34
SLIDE 34

Bakery++

Bakery++ is a slightly modified version of the Bakery algorithm. We call it “Bakery++” because it is almost identical to Bakery. It does not use any additional variables.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 10 /15

slide-35
SLIDE 35

Bakery++

Bakery++ is a slightly modified version of the Bakery algorithm. We call it “Bakery++” because it is almost identical to Bakery. It does not use any additional variables. It does not redefine the operators or functions used in Bakery.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 10 /15

slide-36
SLIDE 36

constant M; integer array choosing [1..N], number [1..N]; begin integer j; L1: if ∃ q ∈ {1, … , N} such that number[q] ≥ M then goto L1; choosing[i] := 1; number[i] := maximum (number[1], … , number[N]); if number[i] ≥ M then begin number[i] := 0; choosing[i] := 0; goto L1; end else number[i] := number[i] + 1; choosing[i] := 0; for j = 1 step 1 until N do begin L2: if choosing[j] ≠ 0 then goto L2; L3: if number[j] ≠ 0 and (number[j], j < number[i], i) then goto L3; end; critical section; number[i] := 0; noncritical section; goto L1; end

Bakery++ (cont.)

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 11 /15

slide-37
SLIDE 37

Performance and Practicality

Bakery++ does not introduce new variables, so the spatial complexities of both algorithms are identical.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 12 /15

slide-38
SLIDE 38

Performance and Practicality

Bakery++ does not introduce new variables, so the spatial complexities of both algorithms are identical. The temporal complexity of Bakery++ depends on the number of executions of the goto statement exactly after label L1.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 12 /15

slide-39
SLIDE 39

Performance and Practicality

Bakery++ does not introduce new variables, so the spatial complexities of both algorithms are identical. The temporal complexity of Bakery++ depends on the number of executions of the goto statement exactly after label L1. The reason Bakery ++ is useful in practice is that it is almost as simple as the original Bakery, without new variables and fancy operations or functions.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 12 /15

slide-40
SLIDE 40

Performance and Practicality

Bakery++ does not introduce new variables, so the spatial complexities of both algorithms are identical. The temporal complexity of Bakery++ depends on the number of executions of the goto statement exactly after label L1. The reason Bakery ++ is useful in practice is that it is almost as simple as the original Bakery, without new variables and fancy operations or functions. There are no practical limitations for implementing the Bakery++ algorithm.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 12 /15

slide-41
SLIDE 41

Correctness Argument

Bakery++ does not introduce new variables and its control flow is almost identical to

  • Bakery. The changes that have been made to Bakery include:
  • Introducing a constant that represents the maximum value storable.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 13 /15

slide-42
SLIDE 42

Correctness Argument

Bakery++ does not introduce new variables and its control flow is almost identical to

  • Bakery. The changes that have been made to Bakery include:
  • Introducing a constant that represents the maximum value storable.
  • Adding a conditional statement and a goto after label L1 that does not manipulate

the values of Bakery’s data objects.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 13 /15

slide-43
SLIDE 43

Correctness Argument

Bakery++ does not introduce new variables and its control flow is almost identical to

  • Bakery. The changes that have been made to Bakery include:
  • Introducing a constant that represents the maximum value storable.
  • Adding a conditional statement and a goto after label L1 that does not manipulate

the values of Bakery’s data objects.

  • Adding a conditional statement before incrementing the maximum value obtained

from reading all processes’ variable number.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 13 /15

slide-44
SLIDE 44

Correctness Argument

Bakery++ does not introduce new variables and its control flow is almost identical to

  • Bakery. The changes that have been made to Bakery include:
  • Introducing a constant that represents the maximum value storable.
  • Adding a conditional statement and a goto after label L1 that does not manipulate

the values of Bakery’s data objects.

  • Adding a conditional statement before incrementing the maximum value obtained

from reading all processes’ variable number.

  • If there is a possibility of overflow in process i, then we simply set

number[i] = choosing[i] = 0 and then we jump to label L1. Otherwise, we will continue by incrementing the maximum value and the original Bakery algorithm.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 13 /15

slide-45
SLIDE 45

Discussion and Future Work

There are two questions: 1. What happens if there are more customers in the bakery than the maximum number that can be stored in a register? 2. What is the definition of the exact moment when a process is considered to have taken its turn for entering its critical section?

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 14 /15

slide-46
SLIDE 46

Conclusions

We revisited the problem of mutual exclusion and the Bakery algorithm, the first true mutual exclusion algorithm, to solve the problem of integer overflow.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 15 /15

slide-47
SLIDE 47

Conclusions

We revisited the problem of mutual exclusion and the Bakery algorithm, the first true mutual exclusion algorithm, to solve the problem of integer overflow. Previous approaches to solving the problem of register overflow concentrated on making use of new variables and redefining the operations or functions used in the original Bakery, and they were complicated solutions.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 15 /15

slide-48
SLIDE 48

Conclusions

We revisited the problem of mutual exclusion and the Bakery algorithm, the first true mutual exclusion algorithm, to solve the problem of integer overflow. Previous approaches to solving the problem of register overflow concentrated on making use of new variables and redefining the operations or functions used in the original Bakery, and they were complicated solutions. Bakery ++ is quite simple and it differs from Bakery in just a few instructions.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 15 /15

slide-49
SLIDE 49

Conclusions

We revisited the problem of mutual exclusion and the Bakery algorithm, the first true mutual exclusion algorithm, to solve the problem of integer overflow. Previous approaches to solving the problem of register overflow concentrated on making use of new variables and redefining the operations or functions used in the original Bakery, and they were complicated solutions. Bakery ++ is quite simple and it differs from Bakery in just a few instructions. We have specified Bakery++ in the PlusCal language and performed model checking.

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm 15 /15

slide-50
SLIDE 50

Thank you!

SRMPDS ‘20, Edmonton, AB, Canada Avoiding Register Overflow in the Bakery Algorithm