Concurrent Programming CT074-3-2
Concurrent Programming
Abstraction
Learning Outcomes
At the end of this module, you should be able to do the
following:
1. Explain and apply the fundamental concepts of
concurrency in the design and construction of a
concurrent system using Java application.
2. Discuss the safety aspects of multi threaded system
3. Discuss the need for encapsulation in concurrent
systems
CT074-3-2
Concurrent Programming
The role of abstraction
[Link]:
- the act of considering something as a general quality or characteristic,
apart from concrete realities, specific objects, or actual instances.
- the act of taking away or separating; withdrawal
abstraction is a technique for managing
complexity of computer systems. It works by
establishing a level of complexity on which a
person interacts with the system,
suppressing the more complex details below
the current level.
CT074-3-2
Concurrent Programming
Levels of abstraction
Systems and libraries
OS and librariesoften called Application
Program Interfaces (API)define
computational resources that are available to
the programmer. You can open a file or send
a message by invoking the proper procedure
or function call, without knowing how the
resource is implemented.
CT074-3-2
Concurrent Programming
Levels of abstraction
Programming languages
A programming language enables you to
employ the computational power of a
computer, while abstracting away from the
details of specific architectures.
CT074-3-2
Concurrent Programming
Levels of abstraction
Instruction sets
Most computer manufacturers design and build
families of CPUs which execute the same
instruction set as seen by the assembly language
programmer or compiler writer. The members of a
family may be implemented in totally different
waysemulating some instructions in software or
using memory for registersbut a programmer
can write a compiler for that instruction set
without knowing the details of the implementation.
CT074-3-2
Concurrent Programming
Levels of abstraction
logic gates and implementation by
semiconductors no thanks!
X=y+z -> electrons in chips
CT074-3-2
Concurrent Programming
Software abstraction.
Encapsulation
Concurrency
CT074-3-2
Concurrent Programming
Encapsulation
Data hiding
Achieves abstraction by dividing a software module into a
public specification and a hidden implementation.
Specification describes the available operations on a data
structure or real-world model.
Detailed implementation of the structure or model is written
within a separate module that is not accessible from the
outside.
Changes in internal data representation and algorithm without
affecting the programming of the rest of the system.
Modern programming languages directly support
encapsulation.
CT074-3-2
Concurrent Programming
Encapsulation
CT074-3-2
Concurrent Programming
10
Private!
public class Employee {
private BigDecimal salary = new BigDecimal(50000.00);
public BigDecimal getSalary() {
return salary;
}
public static void main() {
Employee e = new Employee();
BigDecimal sal = [Link]();
}
CT074-3-2
Concurrent Programming
11
Concurrency
Abstraction designed to make it possible
to reason about the dynamic behavior of
programs.
There are no important concepts of
concurrency that cannot be explained at
the higher level of abstraction.
CT074-3-2
Concurrent Programming
12
Concurrent execution as
interleaving of atomic
statements
CT074-3-2
Concurrent Programming
13
Definition
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 is an execution sequence that can occur as
a result of the interleaving. Computations are also called
scenarios.
CT074-3-2
Concurrent Programming
14
Definition
During a computation the control pointer
of a process indicates the next statement
that can be executed by that process.
Each process has its own control pointer.
Alternate terms for this concept are instruction
pointer and location counter.
CT074-3-2
Concurrent Programming
15
Process Control Block (PCB)
CT074-3-2
Concurrent Programming
16
2 processes, p and q
p
q
p2
CT074-3-2
p1, p2
q1, q2
p1
q1
q2 ??
Concurrent Programming
17
Trivial concurrent program
Trivial sequential program
CT074-3-2
Concurrent Programming
18
CT074-3-2
Concurrent Programming
19
Justification of the abstraction
The electrical signals in a computer travel at the
speed of light, about 2 x 108 m/sec, and the
clock cycles of modern CPUs are at least one
gigahertz, so information cannot travel more
than 2 x 108 10-9 = 0.2 m during a clock cycle of
a CPU. There is simply not enough time to
coordinate individual instructions of more than
one CPU.
CT074-3-2
Concurrent Programming
20
CT074-3-2
Concurrent Programming
21
Justification of the abstraction
We will assume that we have a "bird'seye" view of the global state of the
system, and that a statement of one
process executes by itself and to
completion, before the execution of a
statement of another process
commences.
CT074-3-2
Concurrent Programming
22
Question and Answer Session
Q&A
CT074-3-2
Concurrent Programming
23