[ Home | Class Roster | Syllabus | Status | Glossary | Search | Course Notes]
Operating system: provides an environment for the execution of programs by managing the resources that these programs use. Implicit in this management is the controlled access to these resources.
execution of program = process
environment = set of resources needed for program execution (main memory, file system, processor, communications channels, whatever)
Chapter 2.
{P} S {Q}
// "P" is precondition - true before executing "S"
// "S" is a statement in the programming language
// "Q" is the post condition which should be true after executing
"S" (assuming "P" is true before)
{y = 3 AND z = 5} x := y * z; {x = 15}
// there is an obvious rule for ifThenElse
{P} if (B) Then S1 Else S2 {Q} iff
{P AND B} S1 {Q} AND
{P AND NOT B} S2 {Q}
example
{true} if (a < b) Then min = a; else min = b; {min <=a AND min <=b}
// loops involve a loop invariant (induction hypothesis)
int fact = 1;
int n;
int i = 1;
cin >> n;
while(i <n) {
// loop invariant: fact = i!
i++;
fact = fact*i;
}
// invariant AND i == n IMPLIES fact = n!
// how to prove "i==n" when all you know is "NOT(i < n)"?
p. 27 computation is a particular instance of an execution history on a parallel program
Axiom 2.1 (Parallel Execution) and 2.2 (Critical Section)
If {I(r) AND P AND B} S {I(r) AND Q} AND of course no variables in P or Q can be changed by another process (why do I say of course?)
What is variables are changed? e.g.
{x = 0} S1
||
{true} S2: x = 3;
or
{x < y} S1
||
{true} S2: x = 3; y = x + 1;
Figure 2.11
{I(r) = x = y + z} x := 0; // needed to make precondition true {x = 0} add1: begin y := 0; z := 0; {y = 0 AND z = 0 AND I(r)} // true by examination resource r(x,y,z): cobegin {y=0} // true since precondition from above P1: with r when true do {y=0 AND I(r)} // true by precondition begin x = x+1;/*invariant broken*/ y:=1; end {y=1 AND I(r)} // why is the invariant true? {y = 1} || {z=0} P2: with r when true do {z=0 AND I(r)} begin x = x+1; z:=1; end {z=1 AND I(r)} {z = 1} coend {y = 1 AND z = 1 AND I(r)} end {x = 2} // why is this true?
// would the program still
"work" if y and z were eliminated?
// what is purpose of y and z?
// go over axiom 2.3
Figure 2.14
begin x := 0; y:= 0; sem :=1;
{ x = 0 AND y = 0 AND I(r) } // I(r) = {0 <=sem<=1 AND
(0 <= x+y+sem <=1}
resource r(sem,x,y):
cobegin
{x = 0}
P1: with r when sem >0 do
{x = 0 AND I(r)}
begin sem := sem - 1; x
:= x + 1 end
{x = 1 AND I(r)}
P'1: Execute critical section
{x = 1 AND I(r)}
with r when true
do
{x = 1 AND I(r)}
begin sem := sem + 1; x
:= x - 1 end
{x = 0 AND I(r)}
{x = 0}
||
{y = 0}
P2: with r when sem >0 do
{y = 0 AND I(r)}
begin sem := sem - 1; y
:= y + 1 end
{y = 1 AND I(r)}
P'2: Execute critical section
{y = 1 AND I(r)}
with r when true
do
{y = 1 AND I(r)}
begin sem := sem + 1; y
:= y - 1 end
{y = 0 AND I(r)}
{y = 0}
coend
{x = 0 AND y= 0 AND I(r)}
end
Proof: that P1 and P2 cannot both be in their critical sections at the same time
is by contradiction. (see book).
// What is purpose of "x" and "y"?
// theorem 2.1
What is a Process?
What is the address space? memory space, set of shared objects?
Competitive vs collaborative sharing.
Are the mechanisms described in chapter 2
relevant?
What is every process had it's own computer?
Is non-determinism bad? is it avoidable?
Assignment 2: Are critical sections needed if the system
invariants are not violated? Are critical sections important in a distributed
system? |
Guidelines for Assignments:
Assignments must be posted on your web sites. Obviously you should not
copy another student's assignment and treat it as your own. Assignments
are an extension of the class dialog. Basically you get credit for doing
an assignment and no credit for not doing it. Really exception answers get
extra credit. Most assignments require only short answers - but they should be well thought out answers showing insight into the problem. |