comp30112 concurrency
play

COMP30112: Concurrency Topics 4.2: Modelling and Analyzing - PowerPoint PPT Presentation

Topic 4.2: Modelling and Analyzing Interference in FSP COMP30112: Concurrency Topics 4.2: Modelling and Analyzing Interference in FSP Howard Barringer Room KB2.20: email: Howard.Barringer@manchester.ac.uk February 2008 Topic 4.2: Modelling and


  1. Topic 4.2: Modelling and Analyzing Interference in FSP COMP30112: Concurrency Topics 4.2: Modelling and Analyzing Interference in FSP Howard Barringer Room KB2.20: email: Howard.Barringer@manchester.ac.uk February 2008

  2. Topic 4.2: Modelling and Analyzing Interference in FSP Outline Topic 4.2: Modelling and Analyzing Interference in FSP Interference A GUI Example FSP Modelling of the Garden Modelling Locks in FSP

  3. Topic 4.2: Modelling and Analyzing Interference in FSP Outline Topic 4.2: Modelling and Analyzing Interference in FSP Interference A GUI Example FSP Modelling of the Garden Modelling Locks in FSP

  4. Topic 4.2: Modelling and Analyzing Interference in FSP Interference - summary • When 2 or more threads have access to the same object, there is potential for interference between the actions on the object

  5. Topic 4.2: Modelling and Analyzing Interference in FSP Interference - summary • When 2 or more threads have access to the same object, there is potential for interference between the actions on the object • Destructive update caused by arbitrary interleaving of read and write actions is interference

  6. Topic 4.2: Modelling and Analyzing Interference in FSP Interference - summary • When 2 or more threads have access to the same object, there is potential for interference between the actions on the object • Destructive update caused by arbitrary interleaving of read and write actions is interference • Interference leads to unexpected and undesirable behaviour

  7. Topic 4.2: Modelling and Analyzing Interference in FSP Interference - summary • When 2 or more threads have access to the same object, there is potential for interference between the actions on the object • Destructive update caused by arbitrary interleaving of read and write actions is interference • Interference leads to unexpected and undesirable behaviour • The Ornamental Garden (from Magee and Kramer) example is a good demonstration

  8. Topic 4.2: Modelling and Analyzing Interference in FSP Interference - summary • When 2 or more threads have access to the same object, there is potential for interference between the actions on the object • Destructive update caused by arbitrary interleaving of read and write actions is interference • Interference leads to unexpected and undesirable behaviour • The Ornamental Garden (from Magee and Kramer) example is a good demonstration • We will model and analyze the problem in FSP

  9. Topic 4.2: Modelling and Analyzing Interference in FSP Outline Topic 4.2: Modelling and Analyzing Interference in FSP Interference A GUI Example FSP Modelling of the Garden Modelling Locks in FSP

  10. Topic 4.2: Modelling and Analyzing Interference in FSP GUI Example: Ornamental Garden How Many Visitors are in The Garden??

  11. Topic 4.2: Modelling and Analyzing Interference in FSP Desired Behaviour • Again, two processes reading and updating a common object

  12. Topic 4.2: Modelling and Analyzing Interference in FSP Desired Behaviour • Again, two processes reading and updating a common object • Complexity due to GUI. . .

  13. Topic 4.2: Modelling and Analyzing Interference in FSP Desired Behaviour • Again, two processes reading and updating a common object • Complexity due to GUI. . . • . . . and persuading the code/scheduler to Do The Wrong Thing!!!

  14. Topic 4.2: Modelling and Analyzing Interference in FSP Oh Dear!! ... It’s Gone Wrong

  15. Topic 4.2: Modelling and Analyzing Interference in FSP Ornamental Garden: Class Structure Applet Thread Garden Turnstile Counter people increment() east, west init() run() go() display display eastD, NumberCanvas westD, counterD setvalue()

  16. Topic 4.2: Modelling and Analyzing Interference in FSP The Garden Class public class Garden extends Applet { private void go() { counter = new Counter(counterD); west= new Turnstile(westD,counter); east= new Turnstile(eastD,counter); west.start(); east.start(); }

  17. Topic 4.2: Modelling and Analyzing Interference in FSP The Counter Class class Counter { int value=0; NumberCanvas display; Counter(NumberCanvas n) { display=n; display.setvalue(value); } void increment() { int temp = value; //read[v] Simulate.HWinterrupt(); value=temp+1; //write[v+1] display.setvalue(value); } }

  18. Topic 4.2: Modelling and Analyzing Interference in FSP The Turnstile Class class Turnstile extends Thread { NumberCanvas display; Counter people; Turnstile(NumberCanvas n,Counter c) { display = n; people = c; } public void run() { try{ display.setvalue(0); for (int i=1;i<=Garden.MAX;i++){ Thread.sleep(500); //0.5 second display.setvalue(i); people.increment(); } } catch (InterruptedException e) {} } }

  19. Topic 4.2: Modelling and Analyzing Interference in FSP Simulation of Hardware Interruption class Simulate { public static void HWinterrupt() { if (Math.random()<0.5) try{ Thread.sleep(200); } catch(InterruptedException e){}; } }

  20. Topic 4.2: Modelling and Analyzing Interference in FSP Outline Topic 4.2: Modelling and Analyzing Interference in FSP Interference A GUI Example FSP Modelling of the Garden Modelling Locks in FSP

  21. Topic 4.2: Modelling and Analyzing Interference in FSP Ornamental Garden: FSP Model const N = 4 range T = 0 .. N set VarAlpha = { value . { read [ T ] , write [ T ] }} VAR = VAR [ 0 ] , VAR [ u : T ] = ( read [ u ] → VAR [ u ] | write [ v : T ] → VAR [ v ]) . TURNSTILE = ( go → RUN ) , RUN = ( arrive → INCREMENT | end → TURNSTILE ) , INCREMENT = ( value . read [ x : T ] → value . write [ x + 1 ] → RUN ) + VarAlpha . || GARDEN = ( east : TURNSTILE || west : TURNSTILE || { east , west , display } :: value : VAR ) / { go / { east , west } . go } , end / { east , west } . end } .

  22. Topic 4.2: Modelling and Analyzing Interference in FSP Exhaustive Analysis TEST = TEST[0], TEST[v:T] = (when (v<N){east.arrive,west.arrive}->TEST[v+1] | end->CHECK[v] ), CHECK[v:T] = (display.value.read[u:T] -> (when (u==v) right -> TEST[v] |when (u!=v) wrong -> ERROR) )+{display.{VarAlpha}}. Now compose TEST in parallel with the GARDEN process ||TESTGARDEN = (GARDEN || TEST). The act of building the above composition will check all possible runs of the GARDEN . And we see it fails.

  23. Topic 4.2: Modelling and Analyzing Interference in FSP Outline Topic 4.2: Modelling and Analyzing Interference in FSP Interference A GUI Example FSP Modelling of the Garden Modelling Locks in FSP

  24. Topic 4.2: Modelling and Analyzing Interference in FSP An FSP Model for Locks LOCK = (acquire -> release -> LOCK). ||LOCKVAR = (LOCK || VAR) . set VarAlpha = {value.{read[T],write[T], acquire,release}} INCREMENT = (value.acquire -> value.read[x:T] -> value.write[x+1] -> value.release -> RUN ) + VarAlpha.

  25. Topic 4.2: Modelling and Analyzing Interference in FSP Include in the FSP GARDEN model and .. . . . ||GARDEN = (east:TURNSTILE || west:TURNSTILE || east,west,display::value:LOCKVAR) /{go /{east,west}.go, end/{east,west}.end}. and re-test ||TESTGARDEN = (GARDEN || TEST). And the composition occurs without ERRORs.

  26. Topic 4.2: Modelling and Analyzing Interference in FSP Synchronized Counter For the Java version, create an extension of the Counter that has a synchronised increment() method.

  27. Topic 4.2: Modelling and Analyzing Interference in FSP Synchronized Counter For the Java version, create an extension of the Counter that has a synchronised increment() method. class SynchronizedCounter extends Counter { SynchronizedCounter(NumberCanvas n) super(n); synchronized void increment() { super.increment(); } }

  28. Topic 4.2: Modelling and Analyzing Interference in FSP Synchronized Counter For the Java version, create an extension of the Counter that has a synchronised increment() method. class SynchronizedCounter extends Counter { SynchronizedCounter(NumberCanvas n) super(n); synchronized void increment() { super.increment(); } } and use SynchronizedCounter in place of Counter .

  29. Topic 4.2: Modelling and Analyzing Interference in FSP Synchronized Counter For the Java version, create an extension of the Counter that has a synchronised increment() method. class SynchronizedCounter extends Counter { SynchronizedCounter(NumberCanvas n) super(n); synchronized void increment() { super.increment(); } } and use SynchronizedCounter in place of Counter . (This is used in the applet when the “fix it” checkbox is checked)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend