Lec2 - Todays and next lecture To discuss concurrency...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS3211 – Parallel & Concurrent Programming Concurrency Concepts Abhik Roychoudhury National University of Singapore abhik@comp.nus.edu.sg CS3211 2009-10 by Abhik 1 Chapter 4 of “Principles of the Spin Model Checker” by Ben-Ari, and http://spinroot.com/spin/Man/ (lot of online material, including a Manual) Today’s and next lecture ` To discuss concurrency concepts ` We use Promela, a low-level modeling language. ` We then move to concurrent programming ` We then use Java, a multi-threaded programming language. ` So far … ` Promela as a language ` Basic constructs: if, do, … CS3211 2009-10 by Abhik 2 Example: ABP ` Alternating Bit Protocol ` Reliable channel communication between sender and receiver. ` Exchanging msg and ack. ` Channels are lossy ` Attach a bit with each msg/ack. ` Proceed with next message if the received bit matches your expectation. CS3211 2009-10 by Abhik 3 ` chan datachan = [2] of { bit }; ` chan ackchan = [2] of { bit }; ABP architecture Implemented as Promela processes CS3211 2009-10 by Abhik 4 sender receiver datachan ackchan Sender Receiver active proctype Sender() { bit out, in; do :: datachan!out -> ackchan?in; if active proctype Receiver() { bit in ; do :: datachan?in -> ackchan!in :: timeout -> ackchan!in CS3211 2009-10 by Abhik 5 if :: in == out -> out = 1- out; :: else fi od } :: timeout > ackchan!in od } Timeouts ` Special feature of the language ` Time independent feature. ` Do not specify a time as if you are programming. ` True if and only if there are no executable statements in any of the currently active processes. ` True modeling of deadlocks in concurrent systems (and the CS3211 2009-10 by Abhik 6 resultant recovery).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Something to think about Phil. 1 Phil. 5 Chopstick 1 Chopstick 2 Chopstick 5 CS3211 2009-10 by Abhik 7 Rice Bowl Phil. 2 Phil. 3 Phil. 4 Chopstick 3 Chopstick 4 The task – Exercise for you ` Design the philosopher and the fork processes in Promela such that ` A philosopher eats only when he has both chopsticks – left and right ` No two philosophers hold the same chopstick simultaneously CS3211 2009-10 by Abhik 8 ` No deadlock (circular wait among processes) and ` No starvation (literally so!) ` How will the processes communicate? ` Any of the mechanisms learnt today An approach that does not work Modeling philosopher[i] While (true){ wait for fork[i]; wait for fork[i+1]; ea eat release fork[i]; release fork[i+1]; } Deadlock – each philosopher may pick up their left fork first, and keep on waiting for the right fork. CS3211 2009-10 by Abhik 9 Asymmetric solution ` The first four philosophers execute the same code, but the fifth philosopher executes the following. Loop forever think CS3211 2009-10 by Abhik 10 wait(fork[0]) wait(fork[4]) eat release(fork[0]) release(fork[4]) End loop Today’s lecture ` Dining Philosophers’ problem ` To discuss concurrency concepts ` We use Promela, a low-level modeling language . ` We then move to concurrent programming ` We then use Java, a multi-threaded programming language.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Lec2 - Todays and next lecture To discuss concurrency...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online