









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Paper; Professor: Dillon; Class: Organization Programming Lang; Subject: Computer Science & Engineering; University: Michigan State University; Term: Fall 2006;
Typology: Papers
1 / 15
This page cannot be seen from the preview
Don't miss anything!










Edward A. Lee EECS Department University of California at Berkeley January 2006 “ They [threads] discard the most essential and appealing properties of sequential computation: understandability, pre- dictability, and determinism. Threads... are wildly nonde- terministic, and the job of the programmer becomes one of pruning that nondeterminism. ”
Notation: B = {0, 1} (^) binary digits N = {0, 1, 2, ...} (^) natural numbers B ** = B
, B ~ sequences of 0’s and 1’s B ** < B ** partial functions over B ** Defn1. An imperative machine is a pair ( A, c ) where
** .
** .
Defn3. A sequential program p of length m is a sequence of in- structions p : N" A where p ( n ) = halt , for all n $ m. Defn4. A thread is an execution of a sequential program p on a machine ( A,c ) which is defined by a sequence on B ** , b 0 , b 1 , b 2 , ..., where b n+ = p ( c ( b n ) ) ( b n ) for n $ 0.
state/I/O after n th instruction the ( n+1 ) st instruction state/I/O after ( n+1 ) st instruction Defn5. An of ( p 1 ; p 2 ), for sequential programs p 1 and p 2 , is a sequence on B ** , b 0 , b 1 , b 2 , ..., where b n+ = choose { p 1 ( c ( b n ))( b n ), p 2 ( c ( b n ))( b n ) } for n $ 0.
Not thread safe:
Listener valueChanged(...) ValueHolder Value value addListener( ... ) setValue( ... ) listeners
public void setValue(int nv) { value = nv; Iterator i = listeners.iterator(); while (i.hasNext()) { ((Listener)i.next()).valueChanged(nv); } } public void addListener(Listener nlis) { listeners.add(nlis); } T1: Thread : ValueHolder T1: Thread addListener(...) setValue(...) Data Race!
T1: Thread T1: Thread a: ValueHolder setValue(...) High-level race! b: Listener valueChanged(...) setValue(...) valueChanged(...) synchronized void setValue(int nv) { List copy; synchronized(this) { value = nv; copy = new LinkedList(listeners); } Iterator i = copy.iterator(); while (i.hasNext()) { ((Listener)i.next()).valueChanged(nv); } } Listener valueChanged(...) ValueHolder Value value addListener( ... ) setValue( ... ) listeners
− inflexible and brittle − non compositional ◊ locks needed are not specified in interface − symmetric access becomes very difficult
− implementing a CP pattern is subtle and tricky − properties of different design patterns do not compose
− Transactions—work on a copy of the data, then commit or abort ◊ Good for intrinsically nondeterminate situations (multiple competing actors) − MapReduce—large scale distributed processing of huge data sets ◊ Encapsulate in libraries for non-experts to use
Rendezvous director Value producer 2 Value producer 1 Value consumer Observer Merge Each icon is a Java program. Rendezvous Director indicates CSP-like composition of components. Merge indicates conditional rendezvous ( possible 3-way rendezvous)
PN director Value producer 2 Value producer 1 Value consumer Observer Merge PN Director indicates components communicate via message passing with unbounded FIFO channels and blocking reads. Annotation on Merge combinator indicates nondeterministic merge.