You are on page 1of 11

6CS5-11 DISTRIBUTED SYSTEM UNIT-2

CONCURRENT PROCESS AND PROGRAMMING

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.

 Heavyweight processes (processes)

 Lightweight processes (threads)

o Many problems can be naturally viewed in a way that leads to concurrent programming.

Thread

In computer science, a thread of execution is the smallest sequence of programmed instructions

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.

• Processes: separate logical address space

• Threads: common logical address space

1
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

2
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

Graph Model for process representation:


Processes are related by their need for synchronization and/or communication.

A special case of synchronization is the precedence relationship between processes.

3
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

LECTURE 2

Client Server Model:


•Interaction through a sequence of requests and responses.

• Service-oriented communication model.

• Higher-level abstraction of IPC than RPC or message passing communication.

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

• There is no global time in distributed systems

• Physical clock: close approximation of real time (both point and interval)

4
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

• Logical clock: preservers only the ordering of events

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.

• Each process Pi in the system maintains a logical clock Ci

• →: happens-before relation to synchronize the logical clock

• a → b: Event a precedes event b

• Within a process, if event a precedes event b, then C(a) < C(b)

5
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

• The logical clock in a process is always incremented by an arbitrary positive number when

events in the process progress

• Processes interact with each other using a pair of send and receive operations: these are

considered events as well Rules for Lamport’s logical clock.

6
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

LECTURE 3

Rules for Lamport’s logical clock:

1. if a → b within the same process then C(a) < C(b)

2. If a is the sending event of Pi and b is the corresponding receiving event of Pj then

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

incremented time stamp)

Implementation of the rules:

1. C(b) = C(a) + d

2. Cj(b) = max(T Sa + d, Cj(b)), T Sa is the timestamp of the sending event

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.

Rules 1 and 2 result in partial ordering, so a third rule can be added:

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

logical clock with a distinct process ID number.

The happens-before relation has an important property: Ci(a) < Cj(b) doesn’t imply a → b, i.e.

we cannot distinguish disjoint events using values of logical clocks.

7
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

EXAMPLE:-

8
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

LECTURE 4

LANGUAGE MECHANISMS FOR SYNCHRONIZATION

Concurrent languages

• Specification of concurrent activities

• Synchronization of processes

• Interprocess communication

• Nonderterministic execution of processes

Language constructs

• Program structure

• Data structure

• Control structure

• Procedure and system call

• Input and output

Synchronization mechanisms and language facilities

9
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

Shared-variable synchronization

• Semaphore and conditional critical region

• Monitor and serializer

• Path expression

Classic Problems

• Critical Section

• Dining Philosophers

• Readers/Writers

• Producer-Consumer

Example: the Reader/Writer Problems

synchronization + concurrency

Basics

• if DB empty, allow anyone in

• if reader in DB, writer not allowed in

• if writer in DB, nobody allowed in

10
6CS5-11 DISTRIBUTED SYSTEM UNIT-2

11

You might also like