CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research...
-
Upload
lauren-thomas -
Category
Documents
-
view
216 -
download
0
Transcript of CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research...
![Page 1: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/1.jpg)
Dynamic Program Analysis and Runtime Systems forReliable Concurrent Software:Introduction & Background
CSE 788.07, Autumn 2011Michael Bond
![Page 2: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/2.jpg)
Introductions
Name Program & year Where are you coming from? Research interests
Or what’s something you find interesting?
Research advisor, if any
![Page 3: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/3.jpg)
Outline
Introductions Motivation: concurrency correctness Course overview & survey Background
Program analysis
![Page 4: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/4.jpg)
Hardware becoming more parallel
(more instead of faster cores)
Software must become more parallel
![Page 5: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/5.jpg)
Writing concurrent software
is notoriously difficult
![Page 6: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/6.jpg)
Writing concurrent software
is notoriously difficult
So is reproducing, diagnosing, and fixing
concurrency bugs
![Page 7: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/7.jpg)
Shared memory programming
Imperative programs Java, C#, C, C++, Python, Ruby
Threads Shared mutable state Lock-unlock, wait-notify, start-join
![Page 8: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/8.jpg)
Concurrency correctness
Atomicity Ordering Sequential consistency
Progress
Programmers use synchronization to enforce these
![Page 9: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/9.jpg)
More synchronizationLess synchronization
More concurrency Less concurrency
![Page 10: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/10.jpg)
More synchronizationLess synchronization
Concurrency bugs: atomicity, order, &sequential consistency violations
More concurrency Less concurrency
![Page 11: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/11.jpg)
More synchronizationLess synchronization
Concurrency bugs: atomicity, order, &sequential consistency violations
More concurrency
Concurrency bugs: deadlocks
Poor performance: lock contention, serialization
Less concurrency
![Page 12: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/12.jpg)
More synchronizationLess synchronization
Concurrency bugs: atomicity, order, &sequential consistency violations
More concurrency
Concurrency bugs: deadlocks
Poor performance: lock contention, serialization
Concurrent & correct
Less concurrency
![Page 13: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/13.jpg)
Amdahl’s Law
Gustafson’s Law
![Page 14: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/14.jpg)
Amdahl’s Law: speedup bounded by sequential
computation
Gustafson’s Law: as problem size grows, sequential part
won’t grow as much
![Page 15: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/15.jpg)
Program analysis:
![Page 16: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/16.jpg)
Program analysis:Ensure some correctness
property*
* Definition for this research area
Check or guarantee
![Page 17: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/17.jpg)
Static analysis Dynamic analysis
Analyze static code Analyze running program
Find errors in any execution Find errors in some real execution
Sound: no false negatives* Unsound: false negatives
Imprecise: false positives Precise: often no false positives
Doesn’t slow running program Slows executing program
![Page 18: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/18.jpg)
Static analysis Dynamic analysis
Analyze static code Analyze running program
Find errors in any execution Find errors in some real execution
Sound: no false negatives* Unsound: false negatives
Imprecise: false positives Precise: often no false positives
Doesn’t slow running program Slows executing program
False positive: reported “bug” isn’t really a bug(declare correct program incorrect)
False negative: miss a bug(declare incorrect program correct)
![Page 19: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/19.jpg)
Static analysis Dynamic analysis
Analyze static code Analyze running program
Find errors in any execution Find errors in some real execution
Sound: no false negatives* Unsound: false negatives
Imprecise: false positives Precise: often no false positives
Doesn’t slow running program Slows executing program
False positive: reported “bug” isn’t really a bug(declare correct program incorrect)
False negative: miss a bug(declare incorrect program correct)
Often dynamically sound:Reports all bugs in this execution
![Page 20: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/20.jpg)
Static analysis Dynamic analysis
Analyze static code Analyze running program
Find errors in any execution Find errors in some real execution
Sound: no false negatives* Unsound: false negatives
Imprecise: false positives Precise: often no false positives
Doesn’t slow running program Slows executing programConservative:1. Concurrent
execution2. Approximating heap3. Dynamic class
loading & reflection
Most realistic executions are on
deployed (production) systems!
![Page 21: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/21.jpg)
Survey
1. Name (& nickname if applicable)2. Program (PhD/master’s) & year (1st, 2nd, etc.)3. Why taking class?4. Research interests & current research advisor (if any)5. Background (grad & undergrad): PL, compilers,
architecture, parallel programming, runtime systems, SE6. Available times on Mondays and Wednesdays7. How likely you’ll stay in class (% or explain)?8. Paper(s) you’d like to present (if any)9. Feedback so far?10.Concerns about forwarding critiques to all?
![Page 22: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/22.jpg)
Dynamic Program Analysis and Runtime Systems forReliable Concurrent Software:Introduction & Background, Day 2
CSE 788.07, Autumn 2011Michael Bond
![Page 23: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/23.jpg)
Questions on class, policies, or material from
last time?
![Page 24: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/24.jpg)
Responding to feedback & clarifying policies
Critiques Critiques sent to everyone, but anonymous Don’t write critique if leading discussion
Discussion leaders Covering in interactive way: paper’s main points,
plus critical analysis & opportunities Send scheduling e-mail: 4 weekdays before class▪ Full availability & current status/outline
Send outline: day before our meeting Volunteer for next time?
![Page 25: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/25.jpg)
Responding to feedback & clarifying policies
Meeting I/we need to talk louder Coffee
Logistics 16 enrolled, ~16 papers replace
presentations? Discussion leader for next time? Dropping/auditing? – contact me Got my e-mail?
![Page 26: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/26.jpg)
For next time
Read papers Meet with group tomorrow Send critique by 5 pm Read critiques before class
Before class: send paper(s) you’d like to present
Also start looking at papers for project topic selection (preliminary proposal due Thursday next week)
![Page 27: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/27.jpg)
For next time
Read papers Meet with group tomorrow Send critique by 5 pm Read critiques before class
Before class: send paper(s) you’d like to present
Also start looking at papers for project topic selection (preliminary proposal due Thursday next week)
Questions?
![Page 28: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/28.jpg)
Forming groups
1–2 or 2–3: SJ 11–12: MFS Another time (8:30–10:30, 11:30–
1:30): DH
Will you have time to write critiques after meeting?
![Page 29: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/29.jpg)
Motivation for course content
Critiques & discussions – critically evaluate research & develop new ideas; understand ideas & concepts deeply
Project – practice research process; make research contribution
Motivation for material – more in 885
![Page 30: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/30.jpg)
Concurrency exceptions?!
Java provides memory & type safety
![Page 31: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/31.jpg)
Concurrency exceptions?!
Java provides memory & type safety Buffer overflows, dangling pointers,
array out-of-bounds, double frees, some memory leaks
How are these handled? With exceptions?
![Page 32: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/32.jpg)
Concurrency exceptions?!
Java provides memory & type safety Buffer overflows, dangling pointers,
array out-of-bounds, double frees, some memory leaks
How are these handled? With exceptions?
Should languages, runtime, & hardware systems provide concurrency correctness?
![Page 33: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/33.jpg)
Concurrency exceptions
Data-race freedom & sequential consistency
Locking discipline Atomicity
![Page 34: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/34.jpg)
Concurrency exceptions & enforcement
Data-race freedom & sequential consistency
Locking discipline Atomicity
Also: enforcing atomicity Also: record & replay
![Page 35: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/35.jpg)
Concurrency exceptions & enforcement
Data-race freedom & sequential consistency
Locking discipline Atomicity
Also: enforcing atomicity Also: record & replay
Advantages of exceptions vs. enforcement?
Easier to provide exceptions vs. enforcement?
![Page 36: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/36.jpg)
Concurrency exceptions & enforcement
Data-race freedom & sequential consistency
Locking discipline Atomicity
Also: enforcing atomicity Also: record & replay
Advantages of exceptions vs. enforcement?Easier to provide exceptions vs.
enforcement?
Questions or other issues in paper?
![Page 37: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/37.jpg)
Data races & sequential consistency
Two accesses to same variable At least one is a write
Not well-synchronized(not ordered by happens-before relationship)
Or: accesses can happen simultaneously
![Page 38: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/38.jpg)
Is there a data race?
T1:
data = ...;flag = true;
38
T2:
if (flag)
... = data;
Initially:
int data = 0;
boolean flag = false;
![Page 39: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/39.jpg)
Is there a data race?
T1:
data = ...;flag = true;
39
T2:
if (flag)
... = data;
Initially:
int data = 0;
boolean flag = false;
![Page 40: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/40.jpg)
Is that really so bad?
T1:
data = ...;flag = true;
40
T2:
if (flag)
... = data;
Initially:
int data = 0;
boolean flag = false;
![Page 41: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/41.jpg)
Is that really so bad?
T1:
flag = true;
data = ...;
41
T2:
if (flag)
... = data;
Initially:
int data = 0;
boolean flag = false;
![Page 42: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/42.jpg)
Is that really so bad?
T1:
flag = true;
data = ...;
42
T2:
if (flag)
... = data;
Initially:
int data = 0;
boolean flag = false;
Why a sequential consistency violation?
![Page 43: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/43.jpg)
Is that really so bad?
T1:
data = ...;flag = true;
43
T2:
tmp = data;
if (flag)
... = tmp;
Initially:
int data = 0;
boolean flag = false;
![Page 44: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/44.jpg)
Is there a data race?
T1:
data = ...;synchronized (m) { flag = true;}
44
T2:
boolean tmp;
synchronized (m) {
tmp = flag;
}
if (tmp)
... = data;
Initially:
int data = 0;
boolean flag = false;
![Page 45: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/45.jpg)
Is there a data race?
T1:
data = ...;acquire(m); flag = true;release(m);
45
T2:
boolean tmp;
acquire(m);
tmp = flag;
release(m);
if (tmp)
... = data;
Initially:
int data = 0;
boolean flag = false;
Happens-beforerelationship
![Page 46: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/46.jpg)
Is there a data race?
T1:
data = ...;flag = true;
46
T2:
if (flag)
... = data;
Initially:
int data = 0;
volatile boolean flag = false;
Happens-beforerelationship
![Page 47: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/47.jpg)
Concurrency exceptions & enforcement
Data-race freedom & sequential consistency
Locking discipline Atomicity
Also: enforcing atomicity Also: record & replay
Advantages of exceptions vs. enforcement?
Easier to provide exceptions vs. enforcement?
![Page 48: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/48.jpg)
Additional slides (if time)
![Page 49: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/49.jpg)
Another example: double-checked locking
class Movie { Set<String> comments;
addComment(String s) { if (comments == null) { comments = new HashSet<String>(); } comments.add(s); }}
![Page 50: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/50.jpg)
Another example: double-checked locking
class Movie { Set<String> comments;
addComment(String s) { synchronized (this) { if (comments == null) { comments = new HashSet<String>(); } } comments.add(s); }}
![Page 51: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/51.jpg)
Another example: double-checked lockingclass Movie { Set<String> comments;
addComment(String s) { if (comments == null) { synchronized (this) { if (comments == null) { comments = new HashSet<String>(); } } } comments.add(s); }}
![Page 52: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/52.jpg)
Another example: double-checked locking
addComment(String s) { if (comments == null) { synchronized (this) { if (comments == null) { comments = new
HashSet<String>(); } } } comments.add(s);}
addComment(String s) {
if (comments == null) {
synchronized (this) {
if (comments == null) {
comments =
new HashSet<String>();
}
}
}
comments.add(s);
}
![Page 53: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/53.jpg)
Another example: double-checked locking
addComment(String s) { if (comments == null) { synchronized (this) { if (comments == null) { HashSet temp = alloc HashSet; temp.<init>(); comments = temp; } } } comments.add(s);}
addComment(String s) {
if (comments == null) {
synchronized (this) {
if (comments == null) {
comments =
new HashSet<String>();
}
}
}
comments.add(s);
}
![Page 54: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/54.jpg)
Another example: double-checked locking
addComment(String s) { if (comments == null) { synchronized (this) { if (comments == null) { HashSet temp = alloc HashSet; temp.<init>(); comments = temp; } } } comments.add(s);}
addComment(String s) {
if (comments == null) {
synchronized (this) {
if (comments == null) {
comments =
new HashSet<String>();
}
}
}
comments.add(s);
}
![Page 55: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/55.jpg)
Atomicity violation without data races
55
class Vector { synchronized boolean contains(Object o) { ... } synchronized void add(Object o) { ... }}
![Page 56: CSE 788.07, Autumn 2011 Michael Bond. Name Program & year Where are you coming from? Research interests Or what’s something you find interesting?](https://reader030.fdocuments.in/reader030/viewer/2022032518/56649cce5503460f949989ca/html5/thumbnails/56.jpg)
Atomicity violation without data races
56
class Vector { synchronized boolean contains(Object o) { ... } synchronized void add(Object o) { ... }}
class Set { Vector vector; void add(Object o) { if (!vector.contains(o)) { vector.add(o); } }}