concurrent program

Chapters 1 & 2
Concurrency
and
Abstraction
1
Sequential & Concurrent Execution



A sequential process is an activity resulting from the
execution of a program with its data on a sequential
processor [Shaw, Logical Design of O/S]
Concurrent execution means sequential processes
whose execution are overlapped even in part (paralel
sometimes)
Concurrent languages : Concurrent Pascal, Modula,
Ada, Occam, Linda etc.
2
Concurrent Programming Abstraction

Definition 2.1
 A concurrent program consists of a finite set of (sequential)
processes.
 The processes are written using a finite set of atomic
statements.
 The execution of a concurrent program proceeds by
executing a sequence of the atomic statements obtained
by arbitrarily interleaving the atomic statements from the
processes.
 A computation (a scenario) is an execution sequence that
can occur as a result of the interleaving
3

Definition 2.2
During a computation the control pointer (instruction
pointer, location counter) of a process indicates the next
statement that can be executed by the process.
 Each process has its own control pointer

4
Interleaving of Processes

Suppose we have two processes,



p composed of statements p1 followed by p2
q composed of statements q1 followed by q2
The execution is started with the control pointers of the two
processes pointing to p1 and q1

Possible scenarios of interleaving are shown below

Note that p2 -> p1 -> q1 ->q2 is not a scenario because p2
can not be executed before p1
5
Notation



The program has a title followed by declarations of global variables followed by
processes in columns.
Each process may have declarations of local variables followed by the statements of a
process
Each labeled line in the code is assumed to be an atomic statement
6
State of a Concurrent Algorithm

Definition 2.3

The state of a (concurrent) algorithm is a tuple (a pair, a
triple, a quadruple, etc.) consisting of one element for
each process that is a label from that process (next
statement), and one element for each global or local
variable that is a value whose type is the same as the type
of the variable.
7
State Diagram of the
Sequential Program

A node is a state, arrows are transitions, and the short arrow on the
left is the initial state
8
State Diagram of the
Concurrent Program


Left hand states: p1 followed by q1
Right hand states: q1 followed by p1
9
Scenarios


A scenario is defined by a sequence of states
A scenario can be represented as a state table instead of a
state graph which may be difficult to draw for complicated
programs
A scenario for the
trivial concurrent
program shown as a
sequence of states
10
Atomic Statements


The concurrent programming abstraction presented
so far has been defined in terms of the interleaving
of atomic statements
An atomic statement is a statement which is
executed to completion without the possibilty of
interleaving statements from another process. In
other words, we assume that it is uninterruptable.
11
Algorithm with Atomic Assignment
Statements


Consider the following algorithm and its two possible scenarios
In both scenarios, the final value of the global variable n is 2
12
Modified Algorithm

In the following form of the previous algorithm,
each atomic reference refers the global variable n at
most once
13
A Correct Scenario

In this scenario, the final value of the global variable
n is 2
14
An Incorrect Scenario



The final value of the global variable n is 1 which is not correct
Rule of the book : Assignment statements are atomic statements, as
are evaluations of boolean conditions in control statements
The rule is not realistic but we will use it in order to be able to test the
correctness of concurrent programs
15