Concurrent Process and Programming: Processs and Threads Processes
Concurrent Process and Programming: Processs and Threads Processes
Concurrent Process and Programming: Processs and Threads Processes
LECTURE 1
PROCESSS AND THREADS
Processes
o The chief task of an operating system is to manage a set of processes and to perform
work on their behalf.
o So far we have considered processes as independent. They interact in some way with
the operating system, but we have not examined ways in which processes can interact
with each other.
o Processes that interact with each by cooperating to achieve a common goal are
called concurrent processes.
o Many problems can be naturally viewed in a way that leads to concurrent programming.
Thread
that can be managed independently by a scheduler, which is typically a part of the operating
system. The implementation of threads and processes differs between operating systems, but in
most cases a thread is a component of a process. Multiple threads can exist within one process,
executing concurrently and sharing resources such as memory, while different processes do not
share these resources. In particular, the threads of a process share its executable code and the
values of its dynamically allocated variables and non-thread-local global variables at any given
time.
1
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
2
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
3
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
LECTURE 2
Time services
• Clocks are used to represent time (a relative measure of a point of time) and timer (an
absolute measure of a time interval); it is used to describe the occurence of events in three
different ways: – When an event occurs – How long it takes – Which event occurs first
• Physical clock: close approximation of real time (both point and interval)
4
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
Physical clocks:
• Compensating delay:
– UTC sources to time servers
– time servers to clients
• Calibrating discrepancy
Application of physical clocks:
• Protocols rely on a time-out for handling exceptions
• Time stamping for secure internet communication (avoiding play back attacks)
Logical clocks
For many applications, events need not be scheduled or synchronized with respect to the real-
time clock; it is only the ordering of event execution that is of concern. Lamport’s logical clock
is a fundamental concept for ordering of processes and events in distributed systems.
5
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
• The logical clock in a process is always incremented by an arbitrary positive number when
• Processes interact with each other using a pair of send and receive operations: these are
6
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
LECTURE 3
Ci(a) < Cj(b) (can be enforced if the sending process timestamps its logical clock in the message
and receiving process updates its logical clock using the larger of its own clock time and the
1. C(b) = C(a) + d
The happens-before relation describes the causality between two events; it is transitive. Two
events, a and b, are said to be disjoint events and can be run concurrently if neither a → b nor b
→ a.
3 For all events a and b, C(a) 6= C(b) (this must be fulfilled only for disjoint events)
System-wide unique logical clock times for all events can be obtained by concatenating the
The happens-before relation has an important property: Ci(a) < Cj(b) doesn’t imply a → b, i.e.
7
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
EXAMPLE:-
8
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
LECTURE 4
Concurrent languages
• Synchronization of processes
• Interprocess communication
Language constructs
• Program structure
• Data structure
• Control structure
9
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
Shared-variable synchronization
• Path expression
Classic Problems
• Critical Section
• Dining Philosophers
• Readers/Writers
• Producer-Consumer
synchronization + concurrency
Basics
10
6CS5-11 DISTRIBUTED SYSTEM UNIT-2
11