Multiprocessing -Interprocessing communication and process sunchronization,semaphore
Neena R Krishna
• INTERPROCESSOR COMMUNICATION
• PROCESS SYNCHRONIZATION AND
• Independent process cannot affect or be
affected by the execution of another process
• Cooperating process can affect or be affected by
the execution of another process
• Advantages of process cooperation
– Information sharing
• Exchange of data between two or more processes.
– Os provide facilities for IPC.
• IPC facility provides two operations:
send(message)and receive(message) (message size fixed or
• If P and Q wish to communicate, they need to:
–establish a communication link between them
exchange messages via send/receive
• Multiprocessor and multiple memory modules are
connected together via some interconnection
• They fall on two categories:-
THROUGH ADDRESS SPACE SHARING
• Processors exchange information through
their central shared memory system.
• Inter co-ordination through a global memory
shared by all processor.
• Server system that communicate through a
bus and cache memory controller.
• Access to shared memory is balanced
– Symmetric multiprocessor
• Each processor has equal opportunities to
read/write to memory including equal access
• Basic issues in the design of shared memory
system have to be taken in consideration :-
3)Protection and Security
• Determines which process access are possible to
• The latter contain flag that determine the legality
of each access attempt.
• If there are access attempt to resources then until
the desired access is completed, all disallowed
access are attempt and illegal process are blocked.
• Constraints limit the time of access from
sharing processes to shared resource.
• Appropriate synchronization ensures that the
information flows properly and ensure system
PROTECTION AND SECURITY
• It is a system feature that prevents processes
from making arbitrary access to resource
belonging to other processes.
• Sharing and protection are incompatible:-
– Sharing allow access & protection restricts it.
• All communications are done using implicit
loads and stores to a global address space.
• Synchronization and communication are
• Combine the local memory and processor at
each node of the interconnection network.
• There is no global memory.
– Move data from one local memory to another by
means of message passing.
– Done by a send/reciever pair of commands and
dealing consistency issues.
– Eg: c.1990 Ncube.
• A node in message passing system of
processor and its local memory.
• They are able to store message buffers and
able to perform send/receive operation at the
same time as processing.
• Processor do not share a global memory and
each processor has access to its own address
• Required when one process must wait for
another to complete some operation before
– Eg:-one process (called a writer) may be writing
data to a certain main memory area, while
another process (a reader) may be reading data
from that area and sending it to the printer. The
reader and writer must be synchronized so that
the writer does not overwrite.
IMPORTANCE OF SYNCHRONIZATION
• Prevention and elimination of race conditions,
deadlocks and starvation.
• Data integrity/consistency.
• Race conditions
– the exact timing in the execution of concurrent
processes is critical
• Critical sections
– part of a program that must be protected from
– usually resolved via mutual exclusion
• Mutual exclusion
– the usage of resources by processes is restricted
– usually: only one process may use one instance of a
TYPES OF SYNCHRONIZATION
• Usually implies that all tasks are involved
• Each task performs its work until it reaches
the barrier. It then stops, or "blocks".
• When the last task reaches the barrier, all
tasks are synchronized.
• What happens from here varies. Often, a
serial section of work must be done. In other
cases, the tasks are automatically released to
continue their work.
Suppose there are 2 processes
– Write-process 1 and Read-process 2
• The LOCK(x) operation may be implemented
Var x:shared integer;
var y: integer;
While y =1 do yx;//wait until gate is open //
x1 //set gate to unavailable status //
• The UNLOCK(x) operation may be
UNLOCK(x): x 0;
• It is a resource that contains an integer value
and allows process to synchronize by testing
and setting this value on a single atomic
– Process that test the value of a semaphore and
sets it to a different value,is guaranteed no other
process will interfere with the operation in the
• Two types of operations :-
FEATURES OF SEMAPHORE
• Semaphores are used to synchronize operations
when processes access a common, limited, and
possibly non-shareable resource.
• Each time a process wants to obtain the resource,
the associated semaphore is tested. A positive,
non-zero semaphore value indicates the resource
• Semaphore system calls will, by default, cause the
invoking process to block if the semaphore value
indicates the resource is not available
TYPES OF SEMPAHORE
• COUNTING SEMAPHORE
– Semaphores controlling access to N (multiple)
resources, thus assuming a range of non-negative
values, are frequently.
• BINARY SEMAPHORE
– Semaphores that control access to a single
resource, taking the value of 0 (resource is in use)
or 1 (resource is available).
var s: semaphore
P(s): MUTEXBEGIN (s)
If s < 0 then
Block the process executing the P(s) and
put it in a FIFO queue associated with the
V(s): MUTEXBEGIN (s)
SS + 1;
If s < 0 then
if an inactive process associated with
semaphore s exists, then wake up the highest
priority blocked process associated with s and
put it in a ready list.
PRODUCER CONSUMER PROBLEM
while(((in+1) % Buffer_Size)==out);