Vous êtes sur la page 1sur 9

CONCURRENCY:

MUTUAL EXCLUSION AND


SYNCHRONIZATION
SUBTOPICS:
-PRINCIPLES OF CONCURRENCY
-MUTUAL EXCLUSION HARDWARE SUPPORT
-SEMAPHORES
-MESSAGE PASSING
CONCURRENCY: MUTUAL EXCLUSION &
SYNCHRONIZATION
CONCURRENCY
o Means that two or more calculations happen within the same time frame.
o The tendency for things to happen at the same time in a system.
o The computation of processes within a time frame to give an impression of
simultaneous execution.
MUTUAL EXCLUSION
o The requirement that when one process is in a critical section that accesses shared
resources, no other process may be in a critical section that accesses
o It ensures that only one process is doing certain things at one time.
o is a program object that prevents simultaneous access to a shared resource.
SYNCHRONIZATION
 With respect to multithreading, synchronization is the capability to control the
access of multiple threads to shared resources.
 Process synchronization means sharing system resources by processes in a such a
way that, Concurrent access to shared data is handled thereby minimizing the
chance of inconsistent data.
SAMPLE SCENARIO OF CONCURRENCY
PRINCIPLES OF CONCURRENCY

 Interleaving and overlapping the execution of process


 Can be viewed as examples of concurrent processing
 Both presents the same problems
 Uniprocessor- the relative speed of execution of processes cannot be predicted
 Depends on activities of other processes
 The way the OS handles interrupts
 Scheduling policies of the OS
MUTUAL EXCLUSION HARDWARE SUPPORT

 Interrupt Disabling
 Uniprocessor system
 Disabling interrupts guarantees mutual exclusion
 Solution in multiprocessor configurations

 Special Machine Instruction


 performed in a single instruction cycle
 access to the memory location is blocked for any other instruction

 Compare & Swap Instruction


 Also called a “compare and exchange instruction”
 A compare is made between a memory value and a test value
 If the values are the same a swap occurs
 Carried out atomically
SEMAPHORES

SEMAPHORES
o Are the variables
o Are used for signaling among processes

Three kinds of operations are performed on semaphores:


1. To initialize the semaphore
2. To increment the semaphore value
3. To decrement the semaphore value

Binary semaphores-take only the values in between 0 to 1


Counting semaphores have the non-negative integer value
Cont. of semaphores

How can processes get the critical section?


o A critical section is controlled by semaphores by ff.
operations:
 Wait:--any process can’t enter into the critical
section.
--semaphore value is decremented
o Signal:--the process can enter into the critical
section
--semaphore value is incremented
Cont. of semaphores
MESSAGE PASSING
 Both synchronization and communication requirements are taken care of by this
mechanism
 More over, this mechanism yields to synchronization methods among distributed
processes.
 Basic primitives are:
--send(destination, message)
--receive(source, message)
Issues in message passing
 Send and receive: could be blocking or non-blocking:
 Blocking send: when a process sends a message it blocks until the message is
received at the destination.
 Non-blocking send: after sending a message the sender proceeds with its
processing w/out waiting for it to reach the destination.
 Blocking receive: when a process executes a receive it waits blocked until the
receive is completed and the required message is received.
 Non-blocking receive: the process executing the receive proceeds w/out waiting
for the message.

Vous aimerez peut-être aussi