Module 3 Concurrency
Module 3 Concurrency
Concurrency,
Scheduling
and Dispatch
1
CONCURRENCY:
3
TWO MODELS FOR CONCURRENT
PROGRAM:
• Other examples of the shared-
memory model:
5
TWO MODELS FOR CONCURRENT
PROGRAM:
Message passing. In the
message-passing model,
concurrent modules interact by
sending messages to each other
through a communication channel.
Modules send off messages, and
incoming messages to each
module are queued up for
handling.
6
TWO MODELS FOR CONCURRENT
PROGRAM:
• A and B might be two computers in a
network, communicating by network
connections.
8
KINDS OF CONCURRENT MODULES:
9
MOTIVATIONS FOR ALLOWING
CONCURRENT EXECUTION:
10
PROBLEMS IN CONCURRENCY:
• Sharing global resources: Sharing of global resources
safely is difficult. If two processes both make use of a
global variable and both perform read and write on that
variable, then the order in which various read and write
are executed is critical.
• Optimal allocation of resources: It is difficult for the
operating system to manage the allocation of resources
optimally.
• Locating programming errors: It is very difficult to
locate a programming error because reports are usually
not reproducible.
• Locking the channel: It may be inefficient for the
operating system to simply lock the channel and
prevents its use by other processes.
11
ADVANTAGES OF CONCURRENCY:
• Running of multiple applications:
It enable to run multiple applications at the same time.
• Better resource utilization:
It enables that the resources that are unused by one
application can be used for other applications.
• Better average response time:
Without concurrency, each application has to be run to
completion before the next one can be run.
• Better performance:
It enables the better performance by the operating
system. When one application uses only the processor
and another application uses only the disk drive then the
time to run both applications concurrently to completion
will be shorter than the time to run each application
consecutively. 12
ISSUES OF CONCURRENCY:
Non-atomic:
Operations that are non-atomic but interruptible by multiple processes
can cause problems.
Race conditions:
A race condition occurs of the outcome depends on which of several
processes gets to a point first.
Blocking:
Processes can block waiting for resources. A process could be
blocked for long period of time waiting for input from a terminal. If the
process is required to periodically update some data, this would be
very undesirable.
Starvation:
It occurs when a process does not obtain service to progress.
Deadlock:
It occurs when two processes are blocked and hence neither can
proceed to execute.
13
SCHEDULER in OPERATING SYSTEM:
• Scheduling is the operating system's process to decide
which process should be allocated to the CPU to
execute several processes.
15
TYPES OF SCHEDULERS:
Short Term Scheduler:
16
TYPES OF SCHEDULERS:
Medium Term Scheduler:
19
DISPATCHER in OPERATING SYSTEM:
• Dispatcher needs to be as fast as possible, as it is run
on every context switch. The time consumed by the
Dispatcher is known as dispatch latency.
20
DISPATCHER RESPONSIBILITIES:
• Switching to user mode: All of the low-level operating
system processes run on the kernel level security
access, but all application code and user issued
processes run in the application space or the user
permission mode. The Dispatcher switches the
processes to the user mode.
21
DISPATCHER RESPONSIBILITIES:
• Initiation of context switch: A context switch is when a
currently running process is halted, and all of its data
and its process control block (PCB) are stored in the
main memory, and another process is loaded in its place
for execution.
22
EXAMPLE OF SCHEDULER AND
DISPATCHER:
23
DIFFERENCE OF SCHEDULE AND
DISPATCHER:
24
DIFFERENCE OF SCHEDULE AND
DISPATCHER:
25
END OF MODULE
26