lecture 7

21
Lecture 7 Discuss midterm Scheduling

Upload: ferris

Post on 06-Jan-2016

46 views

Category:

Documents


5 download

DESCRIPTION

Lecture 7. Discuss midterm Scheduling. Alternative Directory Structure. See hw 1 and hw 2. This one more aligned with UNIX directory structure. Idea for implementing processing is the same: at least conceptually separate traversal from maximum computation. UNIX style directory structure. *. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture 7

Lecture 7

Discuss midterm

Scheduling

Page 2: Lecture 7

Alternative Directory Structure

• See hw 1 and hw 2.

• This one more aligned with UNIX directory structure.

• Idea for implementing processing is the same: at least conceptually separate traversal from maximum computation.

Page 3: Lecture 7

DirectoryDirectoryEntry

INode FileName

Mode

RegularFile

*entries

inodefilename

Sizeint i;

mode

Ident

Block

*blocks

UNIX style directory structure

Page 4: Lecture 7

DirectoryDirectoryEntry

INode FileName

Mode

RegularFile

*entries

inodefilename

Sizeint i;

mode

Ident

Block

*blocks

Maximum RegularFile size

Traversal: from Directory to RegularFile

Page 5: Lecture 7

DirectoryDirectoryEntry_List

INode

Mode

RegularFile

*

entries

inode

Sizeint i;

mode

Maximum RegularFile size: implementation structure

VectorDirectoryEntry

Object

Page 6: Lecture 7

Collecting Informationduring traversal

• Java does not have call by reference like C++ or Pascal.

• Use IntegerRef class instead:class IntegerRef {

private int i_;

IntegerRef(int i) { i = i_;}

public int getValue() {return i_;}

public void setValue(int n) {i_ = n;}

}

Page 7: Lecture 7

From IntegerRef to Visitor pattern

• Using class IntegerRef is not optimal: The code for computing the maximum is mixed with the traversal code.

• A better but more elaborate solution would be to apply the visitor design pattern: instead of an IntegerRef-object, we give a MaxVisitor-object to the traversal.

Page 8: Lecture 7

MaxVisitor

class MaxVisitor {

private int max; int size;

MaxVisitor() { max = 0;}

public int get_result() {return max;}

public void before(INode host)

{size = host.get_size();}

public void before(RegularFile host)

{if (size > max) max=size;}

}

// this visitor takes care of transporting size

// the traversal is: from Directory to RegularFile

Page 9: Lecture 7

DJ

• If you use a library like DJ you can easily program in this style.

• DJ: www.ccs.neu.edu/research/demeter/DJ

• To learn about software development technology in general and Demeter in particular, take the COM 3360 class in the fall of 2000. See my home page.

Page 10: Lecture 7

Vector in Java 2

• Vector now implements ListInterface. Use following idiom to iterate through list:

for (ListIterator I = this.listIterator(); I.hasNext();) {

… I.next(); …

}

• Start using Collection framework as much as possible.

Page 11: Lecture 7

Semaphores in Java:Compare with WaitingStack

public final class CountingSemaphore { private int count_ = 0; public CountingSemaphore(int inC) { count_ = inC;} public void P() { // down -- pop while (count_ = 0) try {wait();} catch (InterruptedException ex) {} --count_;} public void V() { // up -- push ++count_; notifyAll(); }} From: Concurrent Programming in Java by Doug Lea

Page 12: Lecture 7

N1 N2

N1 C2T1 T2T1 T2C1 N2

N1 T2T1 N2

T1 C2C1 T2

0

1

Puzzle: what is this?

Page 13: Lecture 7

State modeling: two-process mutual exclusion

N1 N2

N1 C2T1 T2T1 T2C1 N2

N1 T2T1 N2

T1 C2C1 T2

N: noncritical regionT: trying regionC: critical region 0

1

Note: it is important to havetwo (T1,T2)

Page 14: Lecture 7

State modeling: two-process mutual exclusion

N1 N2

N1 C2T1 T2T1 T2C1 N2

N1 T2T1 N2

T1 C2C1 T2

N: noncritical regionT: trying regionC: critical region 0

1

AF(C1) true in 1EF(C1 and C2) false in 0

Page 15: Lecture 7

Reasoning about concurrency

• Abstract from code

• Computation tree logic reasons about systems at this level

• Uses model-checking techniques

Page 16: Lecture 7

Symbolic Model Checking

• Determine correctness of finite state systems.

• Developed at Harvard and later at CMU by Clarke/Emerson/Sistla

• Specifications are written as formulas in a propositional temporal logic.

• Temporal logic: expressing ordering of events without introducing time explicitly

Page 17: Lecture 7

Temporal Logic

• A kind of modal logic. Origins in Aristotle and medieval logicians. Studied many modes of truth.

• Modal logic includes propositional logic. Embellished with operators to achieve greater expressiveness.

• A particular temporal logic: CTL (Computation Tree Logic)

Page 18: Lecture 7

Computation Tree Logic

• Used to express properties that will be verified

• Computation trees are derived from the state transition graphs

• State transition graphs unwound into an infinite tree rooted at initial state

Page 19: Lecture 7

a

b

b

c

a

c

S0

S0

S1

S2

S1

S1 S2

S2

S0

S1 S0structure

computation tree for S0

Page 20: Lecture 7

Computation Tree Logic

• CTL formulas built from – atomic propositions, where each proposition

corresponds to a variable in the model– Boolean connectives– Operators. Two parts

• path quantifier (A, E)

• temporal operator (F,G,X,U)

Page 21: Lecture 7

Computation Tree Logic

• Paths in tree represent all possible computations in model.

• CTL formulas refer to the computation tree

)( ackAFimpliesreqAGIf the signal req is high then eventually ack will also be high