Sincronizacion
Concurrent Programming
Processes
Concurrent Programming
In a computer system running under an OS, all the
In
runnable software on a computer, including the OS, is
organized into a number of sequential processes (or
processes in short).
processes
Prof. Dr. Alejandro Zunino
In a multiprogramming system, the CPU switches from
In
program to program, giving the users theillusion of
parallelism (pseudo parallelism).
parallelism
ISISTAN – UNICEN
1
2
Process
PCB for P1
P1
A program in execution, consisting of
program
1. program's data and stack (and the memory areas)
1.
2. program counter, stack pointer, and other CPU
program
registers
registers
3. all other information necessary to run the program:
all
process id, priority, accountinginformation, memory
information, open files, process state, etc.
information,
4. executable code (and the memory area)
Note: 2 and 3 are stored in OS data structures called process
Note:
control blocks (PCBs)
control
Note: 4 is sharable among processes
Note:
Clearly understand the difference between program
(executable image) and process
(executable
3
PCB for P2
P2
PCB for P3P3
Process Switching on a single processor
4
Process/Thread States
Created but not yet ready to run
Waiting to gain access to some resource
Distributed Program
A distributed program is a system of programs
distributed
designed to execute simultaneously on a network of
computers.
computers.
Because the individual processes may be executed on
Because
different computers the donot share memory (as
threads do).
threads
Ready to run but needs a processor
Actually executing on a processor
Finished
Distributed programs must communicate using some
Distributed
form of messaging.
form
Multi-threaded programs most often communicate
Multi-threaded
using shared (e.g. non local) variables.
using
6
7
Introduction to Concurrent Programming
Introductionto Concurrent Programming
• Multiple CPUs
What is concurrent programming?
What
A sequential program has a
single thread of control.
A
C
A
B
A concurrent program has
multiple threads of control
allowing it perform multiple
computations in parallel and
to control multiple external
activities which occur at the
same time.
physically
parallel
C
B
Time
•Single CPU
A
instruction
interleaving
B
A
C
B
C
Time
8
9
What is concurrent programming?
Concurrency versus parallelism
processes are always concurrent but not always
processes
parallel
parallel
writing programs that involve more than one process
parallelism means that more than one process is
executing at any given instant => more than one
processorprocessor
concurrency means that more than one process can
concurrency
be under way (exist) simultaneously; but maybe that
only one is executing at any given instant
only
P1 P2
P1 P2
context
switches
(performed
at a time
chosen by
the scheduler)
examples
implementing operating system internals
exploiting multiprocessor machines to make
exploiting
algorithms run faster
algorithmsstructuring inherently concurrent applications
an X server must listen for key presses, mouse clicks
an
and draw requests from programs “at the same time”
and
an animation applet must do the animation, listen for
an
the command to stop, speed up etc. “at the same time”
the
an aircraft control system must respond to joystick,
an
throttle and wind direction sensors “at the same time”throttle
10
11
Why?
Why concurrent programming?
Performance gain from multiprocessing hardware
Performance
parallelism.
parallelism.
Increased application throughput
Increased
an I/O call need only block one thread.
an
Increased application responsiveness
Increased
high priority thread for user requests.
high
More appropriate structure
for programs which interact with...
Regístrate para leer el documento completo.