exam questions revision
play

Exam Questions & Revision DM519 Concurrent Programming 1 1 - PowerPoint PPT Presentation

Exam Questions & Revision DM519 Concurrent Programming 1 1 The Main Aims Of The Course Construct models from specifications of concurrency problems DM519 Concurrent Programming 2 2 The Main Aims Of The Course Construct models from


  1. Exam Questions & Revision DM519 Concurrent Programming 1 1

  2. The Main Aims Of The Course Construct models from specifications of concurrency problems DM519 Concurrent Programming 2 2

  3. The Main Aims Of The Course Construct models from specifications of concurrency problems Test, analyse, and compare models’ behaviour DM519 Concurrent Programming 2 2

  4. The Main Aims Of The Course Construct models from specifications of concurrency problems Test, analyse, and compare models’ behaviour Define and verify models’ safety & liveness properties DM519 Concurrent Programming 2 2

  5. The Main Aims Of The Course Construct models from specifications of concurrency problems Test, analyse, and compare models’ behaviour Define and verify models’ safety & liveness properties Implement models in Java DM519 Concurrent Programming 2 2

  6. The Main Aims Of The Course Construct models from specifications of concurrency problems Test, analyse, and compare models’ behaviour Define and verify models’ safety & liveness properties Implement models in Java Relate models and implementations DM519 Concurrent Programming 2 2

  7. Revision The following is a sample of some of the covered topics CSP DM519 Concurrent Programming 3 3

  8. Outline Of Covered Chapters 2. Processes and Threads 3. Concurrent Execution The main basic 4. Shared Objects & Interference Concepts 5. Monitors & Condition Synchronisation Models 6. Deadlock Practice 7. Safety and Liveness Properties 8. Model-based Design Advanced topics … 9. Dynamic systems 10.Message Passing DM519 Concurrent Programming 4 4

  9. Models: FSP & LTS Model = simplified representation of the real world u Based on Labelled Transition Systems ( LTS ): Focuses on concurrency aspects (of the program) - everything else abstracted away u Described textually as Finite State Processes ( FSP ): EngineOff = (engineOn -> EngineOn), EngineOn = (engineOff -> EngineOff |speed -> EngineOn). DM519 Concurrent Programming 5 5

  10. Finite State Processes (FSP) FSPs can be defined using: P = – x -> Q // action – Q // other process variable – STOP // termination – Q | R // choice – when (...) x -> Q // guard – ... + {write[0..3]} // alphabet extension – X[i:0..N] =x[N-i] -> P // process & action index – BUFF(N=3) // process parameter const N = 3 // constant definitions range R = 0..N // range definitions set S = {a,b,c} // set definitions DM519 Concurrent Programming 6 6

  11. Finite State Processes (FSP) FSPs can be defined using: P = – x -> Q // action – Q // other process variable – STOP // termination – Q | R // choice – when (...) x -> Q // guard – ... + {write[0..3]} // alphabet extension – X[i:0..N] =x[N-i] -> P // process & action index – BUFF(N=3) // process parameter const N = 3 // constant definitions range T = 0..3 range R = 0..N // range definitions BUFF = (in[i:T]->out[i]->BUFF). set S = {a,b,c} // set definitions DM519 Concurrent Programming 6 6

  12. Finite State Processes (FSP) FSPs can be defined using: P = – x -> Q // action – Q // other process variable – STOP // termination – Q | R // choice – when (...) x -> Q // guard – ... + {write[0..3]} // alphabet extension – X[i:0..N] =x[N-i] -> P // process & action index – BUFF(N=3) // process parameter const N = 3 // constant definitions range T = 0..3 range R = 0..N // range definitions BUFF = (in[i:T]->out[i]->BUFF). set S = {a,b,c} // set definitions DM519 Concurrent Programming 6 6

  13. Finite State Processes (FSP) DM519 Concurrent Programming 7 7

  14. Finite State Processes (FSP) FSP: – P || Q // parallel composition – a:P // process labelling (1 process/prefix) – { … }::P // process sharing (1 process w/all prefixes) – P / {x/y} // action relabelling – P \ { … } // hiding – P @ { … } // keeping (hide complement) DM519 Concurrent Programming 7 7

  15. Finite State Processes (FSP) FSP: – P || Q // parallel composition – a:P // process labelling (1 process/prefix) – { … }::P // process sharing (1 process w/all prefixes) – P / {x/y} // action relabelling – P \ { … } // hiding – P @ { … } // keeping (hide complement) ||TWOBUF = (a:BUFF||b:BUFF) /{in/a.in, a.out/b.in, out/b.out} @{in,out}. DM519 Concurrent Programming 7 7

  16. Finite State Processes (FSP) FSP: – P || Q // parallel composition – a:P // process labelling (1 process/prefix) – { … }::P // process sharing (1 process w/all prefixes) – P / {x/y} // action relabelling – P \ { … } // hiding – P @ { … } // keeping (hide complement) ||TWOBUF = (a:BUFF||b:BUFF) /{in/a.in, a.out/b.in, out/b.out} @{in,out}. DM519 Concurrent Programming 7 7

  17. Finite State Processes (FSP) FSP: – P || Q // parallel composition – a:P // process labelling (1 process/prefix) – { … }::P // process sharing (1 process w/all prefixes) – P / {x/y} // action relabelling – P \ { … } // hiding – P @ { … } // keeping (hide complement) ||TWOBUF = (a:BUFF||b:BUFF) Structure Diagrams: /{in/a.in, a.out/b.in, TWOBUFF out/b.out} a:BUFF b:BUFF in a.out @{in,out}. out in out out in DM519 Concurrent Programming 7 7

  18. Structure Diagrams - Resource Sharing RESOURCE = (acquire->release->RESOURCE). USER = (printer.acquire->use->printer.release->USER). DM519 Concurrent Programming 8 8

  19. Structure Diagrams - Resource Sharing RESOURCE = (acquire->release->RESOURCE). USER = (printer.acquire->use->printer.release->USER). ||PRINTER_SHARE = (a:USER || b:USER || {a,b}::printer:RESOURCE). DM519 Concurrent Programming 8 8

  20. Structure Diagrams - Resource Sharing RESOURCE = (acquire->release->RESOURCE). USER = (printer.acquire->use->printer.release->USER). ||PRINTER_SHARE = (a:USER || b:USER || {a,b}::printer:RESOURCE). PRINTER_SHARE a:USER printer printer: RESOURCE acquire b:USER release printer DM519 Concurrent Programming 8 8

  21. How To Create The Parallel Composed LTS MAKE1 = (make-> ready ->STOP). USE1 = ( ready ->use->STOP). ||MAKE1_USE1 = (MAKE1 || USE1). make ready 0,0 1,0 2,0 For any state reachable from the initial state (0,0), consider ready the possible actions and draw ready ready edges ready make 0,1 1,1 2,1 to the corresponding new states (i,j). use use use Remember to consider shared actions. make ready 0,2 1,2 2,2 DM519 Concurrent Programming 9 9

  22. How To Create The Parallel Composed LTS MAKE1 = (make-> ready ->STOP). USE1 = ( ready ->use->STOP). ||MAKE1_USE1 = (MAKE1 || USE1). make ready 0,0 1,0 2,0 For any state reachable from the initial state (0,0), consider ready the possible actions and draw ready ready edges ready make 0,1 1,1 2,1 to the corresponding new states (i,j). use use use Remember to consider shared actions. make ready 0,2 1,2 2,2 DM519 Concurrent Programming 9 9

  23. Chapter 4: Shared Objects & Mutual Exclusion u Concepts: l Process interference l Mutual exclusion u Models: l Model-checking for interference l Modelling mutual exclusion u Practice: l Thread interference in shared objects in Java l Mutual exclusion in Java l Synchronised objects, methods, and statements DM519 Concurrent Programming 10 10

  24. Condition Synchronisation In FSP And Java FSP: when ( cond ) action -> NEWSTATE synchronized void action () throws Int’Exc’ { while (!cond) wait(); // modify monitor data notifyAll(); } The while loop is necessary to re-test the condition cond to ensure that cond is indeed satisfied when it re-enters the monitor. notifyAll() is necessary to awaken other thread(s) that may be waiting to enter the monitor now that the monitor data has been changed. DM519 Concurrent Programming 11 11

  25. Condition Synchronisation (in Java) CONTROL(CAPACITY=4) = SPACES[CAPACITY], SPACES[spaces:0..CAPACITY] = (when(spaces>0) arrive -> SPACES[spaces-1] |when(spaces<CAPACITY) depart -> SPACES[spaces+1]). class CarParkControl { protected int spaces, capacity; synchronized void arrive() throws Int’Exc’ { while (!(spaces>0)) wait(); --spaces; notifyAll(); } synchronized void depart() throws Int’Exc’ { while (!(spaces<capacity)) wait(); ++spaces; notifyAll(); } } DM519 Concurrent Programming 12 12

  26. Condition Synchronisation (in Java) CONTROL(CAPACITY=4) = SPACES[CAPACITY], SPACES[spaces:0..CAPACITY] = (when(spaces>0) arrive -> SPACES[spaces-1] |when(spaces<CAPACITY) depart -> SPACES[spaces+1]). class CarParkControl { protected int spaces, capacity; synchronized void arrive() throws Int’Exc’ { while (!(spaces>0)) wait(); --spaces; notify() instead of notifyAll() ? 1. Uniform waiters - everybody notifyAll(); waits on the same condition } 2. One-in, one-out synchronized void depart() What goes wrong with notify throws Int’Exc’ { and 8xDepartures, 5xArrivals? while (!(spaces<capacity)) wait(); ++spaces; notifyAll(); } } DM519 Concurrent Programming 12 12

  27. Semaphores Semaphores are widely used for dealing with inter-process synchronisation in operating systems. Semaphore s : integer var that can take only non-neg. values. sem.down(); // decrement (block if counter = 0) sem.up(); // increment counter (allowing one blocked thread to pass) DM519 Concurrent Programming 13 13

Recommend


More recommend