cs205: engineering software? |
(none) 05 April 2010 |
cs205 Friday 13 October 2006
Upcoming Schedule
Sam Brunjes, Patrick Harrison, Kramer SharpGrahame Burke, Emily Lam, Rachel Phillips
Michael Lew, Mike Liu, Richard Hsu
What is the difference between an is-a and has-a relationship?
Why is concurrent programming harder than sequential programming?
Why is concurrent programming easier than sequential programming?
class Counter { private int count; public Counter () { count = 0; } public void increment () { count++; } public void decrement () { count--; } public int getValue () { return count; } } class IncThread extends Thread { private Counter c; public IncThread (Counter p_c) { c = p_c; } public void run () { while (true) { c.increment (); System.err.println ("Running inc thread: " + currentThread () + " / Value: " + c.getValue ()); } } } class DecThread extends Thread { private Counter c; public DecThread (Counter p_c) { c = p_c; } public void run () { while (true) { c.decrement (); System.err.println ("Running dec thread: " + currentThread () + " / Value: " + c.getValue ()); } } } public class Yarn { public static void main (String args[]) { Counter c = new Counter (); IncThread ithread = new IncThread (c); DecThread dthread = new DecThread (c); ithread.start (); dthread.start (); } }
What causes a deadlock?
synchronized (expr) { statements }Execution will stall until this thread can acquire the lock associated with expr. The lock is held for the duration of the synchronized statement.