• Keine Ergebnisse gefunden

In the examples, we tend to write the proofs in proof outline mode, by interleaving assertions and program commands. For example, we write:

N/A
N/A
Protected

Academic year: 2021

Aktie "In the examples, we tend to write the proofs in proof outline mode, by interleaving assertions and program commands. For example, we write:"

Copied!
3
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Separation Logic Examples

Viktor Vafeiadis May 1, 2014

1 Proof outline notation

In the examples, we tend to write the proofs in proof outline mode, by interleaving assertions and program commands. For example, we write:

emp x := alloc(0);

x 7→ 0 [x] := 1 x 7→ 1

This is to be read as follows:

• By the Alloc rule, we have:

emp x := alloc(0)

x 7→ 0 .

• By the Write rule, we have:

x 7→ 0 [x] := 1

x 7→ 1 .

• By the Seq rule, we have

emp x := alloc(0); [x] := 1

x 7→ 1 . In the individual steps, we also often freely use the structural rules of sepa- ration logic, ( Frame , Conseq , Disj , Ex ). For example:

x 7→ 0 c := alloc(0);

x 7→ 0 ∗ c 7→ 0

Here, we used consequence rule, the frame rule, and the allocation axiom.

A typical example using the disjunction rule is:

x 7→ 0 ∨ x 7→ 1 t := [x]

x 7→ 0 ∧ t = 0 ∨ x 7→ 1 ∧ t = 1

When for emphasis we want to show the use of the consequence rule, we write the two assertions one after the other. For example, we could have written our earlier step more explicitly as:

x 7→ 0 x 7→ 0 ∗ emp c := alloc(0);

x 7→ 0 ∗ c 7→ 0 For other compound commands, we use similar notation:

P

1

∗ P

2

 P

1

C

1

Q

1

P

2

C

2

Q

2

 Q

1

∗ Q

2

P atomic {

P ∗ J C Q ∗ J }

Q

1

(2)

Finally, we denote applications of the Share rule as:

P ∗ J J `

 P

C Q

 Q ∗ J

2 Ownership Transfer

Let J

def

= c 7→ 0 ∨ c 7→ 1 ∗ x 7→ 1.

emp

x := alloc(0);

x 7→ 0 c := alloc(0);

x 7→ 0 ∗ c 7→ 0 x 7→ 0 ∗ emp ∗ J

J `

x 7→ 0 ∗ emp

x 7→ 0 [x] := 1;

x 7→ 1 atomic {

x 7→ 1 ∗ J x 7→ 1 ∗ c 7→ 0 [c] := 1;

x 7→ 1 ∗ c 7→ 1 emp ∗ J }

emp

emp atomic {

emp ∗ J

c 7→ 0 ∨ c 7→ 1 ∗ x 7→ 1 t := [c];

c 7→ 0 ∧ t = 0 ∨ c 7→ 1 ∗ x 7→ 1 ∧ t = 1

assume(t = 1);

c 7→ 0 ∧ t = 0 ∨ c 7→ 1 ∗ x 7→ 1 ∧ t = 1

∧ t = 1 c 7→ 1 ∗ x 7→ 1

[c] := 0;

c 7→ 0 ∗ x 7→ 1 x 7→ 1 ∗ J }

x 7→ 1 t := [x]

x 7→ 1 ∧ t = 1

 emp ∗ (x 7→ 1 ∧ t = 1)

x 7→ 1 ∧ t = 1 (x 7→ 1 ∧ t = 1) ∗ J c 7→ 0 ∗ x 7→ 1 ∧ t = 1

2

(3)

3 Fractional Permissions

Fractional permissions allow multiple concurrent readers of a memory cell.

For example:

x 7→ 5 n

x

0.3

7→ 5 ∗ x

0.7

7→ 5 o

 n

x

0.3

7→ 5 o t := [x];

n

x

0.3

7→ 5 ∧ t = 5 o

n x

0.7

7→ 5

o u := [x];

n

x

0.7

7→ 5 ∧ u = 5 o

 n

(x

0.3

7→ 5 ∧ t = 5) ∗ (x

0.7

7→ 5 ∧ u = 5) o x 7→ 5 ∧ t = 5 ∧ u = 5

Using fractional permissions, we can also reason about a system where one distinguished thread writes to [x] atomically and knows its value, while other threads simply read from [x] atomically, but cannot assert anything about its value. The trick is to give half of the permission to the resource invariant and keep the other half in the writing thread. Here is an illustra- tion:

x 7→ 5 n

x

0.4

7→ 6 ∗ x

0.6

7→ − o

x

0.6

7→ − ` n

x

0.4

7→ 5 o

 n

x 7→

0.4

5 o t := [x];

n

x 7→

0.4

5 ∧ t = 5 o atomic {

n

(x

0.4

7→ 5 ∧ t = 5) ∗ x

0.6

7→ − o x 7→ 5 ∧ t = 5

[x] := t + 1;

x 7→ 6 ∧ t = 5 n

x

0.4

7→ 6 ∗ x

0.6

7→ − o }

n x 7→

0.4

6

o

emp atomic {

n x

0.6

7→ −

o u := [x];

n x

0.6

7→ −

o }

emp

 n

x

0.4

7→ 6 o n

x

0.4

7→ 6 ∗ x

0.6

7→ − o x 7→ 6

3

Referenzen

ÄHNLICHE DOKUMENTE

But despite my frustrations, I find myself constantly seeking new methods or rituals. I use the word “ritual” quite intentionally here as many people seem to have one. Many

• Only Swiss laboratory for the study of highly radioactive materials:.. − Post irradiation examination of irradiated

Organizarea contabilităţii de gestiune şi calculaţiei costurilor pe baze ştiinţifice în întreprinderile din industria fierului şi oţelului asigură premisele pentru

These structured proofs do not seem ideal for someone who wants to understand the important ideas of a proof without reading any of the details.. Satisfying such readers may

If the indirect object is a pronoun, this word order is more common..  You'll give him

If the indirect object is a pronoun, this word order is more common.. Here are some other verbs that work the

If the indirect object is a pronoun, this word order is more common..  You'll give him

Change the word order and change the indirect object into a pronoun. We sent an application form to