Message
Passing
Operating
Systems
–
BSSE
2
nd
year
4
th
semester
Topics:
Synchronization
Addressing
Message Format
Queueing Discipline
Mutual Exclusion
B19103008
Amaim Shaikh
______________
Message Format
And Queueing
Discipline
B19103019
Hareem Saad
______________
Synchronization
B19103047
Neha Haroon
______________
Addressing
B19103065
Syeda Sughra
Raza
______________
Mutual
Exclusion
1.
Message
Passing
Message passing is a technique
for invoking behavior (i.e.,
running a program) on a
computer.
4
Message passing is the sharing of data by sending and receiving messages
between the processes.
Message passing satisfies the requirements of interaction between processes
i.e., synchronization and communication. Moreover, mutual exclusion can
only be carried out if processes are synchronized.
Physical implementation
● Single processor system
● Multiprocessor system
● Distributed system
The two
operations of
message passing
5
It's the method used by a process to send a
message to another process
The syntax is
Send (destination, message)
It's the method used by a process to receive a
message by another process
The syntax is
Receive (source, message)
Send Receive
2.
Synchronization
Process Synchronization is a way
to coordinate processes that use
shared data.
What Happens to a
process after it issues
a send primitive?
7
If the process resumes its work after sending a
message i.e. does not wait till the destination
process has received the message
If the process does not resumes its work after
sending a message i.e. it waits till the
destination process has received the message
Non-blocking Send Blocking send
What Happens to a
process after it issues
a receive primitive?
8
If the process performs its work even if no
message has been received i.e. it does not wait
till the it has received the message to start work
if a valid message exists it issues it otherwise it
issues a null message
If the process cannot perform its work until
after the message is received i.e. it waits till it
has received the message to start working
Non-blocking receive Blocking receive
In any system three
combinations of the above
primitives may occur
9
Blocking send,
blocking receive
Both the sender and receiver
are blocked until the message
has been delivered
It is sometimes referred to as a
rendezvous
Allows tight synchronization
sender continues on, while the
receiver is blocked until the
requested message arrives
It allows a process to send one
or more messages to a variety
of destinations as quickly as
possible
A process that must receive a
message before it can do useful
work needs to be blocked until
such a message arrives
Non-blocking send,
non-blocking receive
Neither party is required to
wait
Non-blocking send,
blocking receive
EXAMPLE
A process requests printing, it send the a message to
issue the request in the form of a message and then
carry on
DANGER
Due to the absence of blocking an error could lead to a
situation in which a process repeatedly generates
messages. Which would consume system resources,
including processor time and buffer space.
SOLUTION
The non-blocking send places the burden on the
programmer to determine that a message has been
received: Processes must employ reply messages to
acknowledge receipt of a message.
Non-blocking
send
02
03
01
EXAMPLE
A process requests printing, it send the a message to issue the request in the form of a
message and then carry on
DANGER
If a message is lost, which can happen in a distributed system, or if a process fails before
it sends an anticipated message, a receiving process could be blocked indefinitely.
SOLUTION
We can use a non-blocking receive to avoid the problem, but in that approach if the
message has been sent after the receiving process has been executed the message will be
lost forever.
Other possible approaches are to allow a process to test whether a message is waiting
before issuing a receive and allow a process to specify more than one source in a receive
primitive. The latter approach is useful if a process is waiting for messages from more
than one source and can proceed if any of these messages arrive.
Blocking Receive
02
03
01
3.
Addressing
Way of specifying :
In send primitive: who is to receive the message
In receiver primitive: who is source for message
TYPES :
1. Direct Addressing
2. Indirect Addressing
?
?
?
?
Direct
Addressing
13
Includes a specific identifier of
destination process
Send (destination, message)
Includes a source process (receiver must
know ahead of time which process to
expect as a source)
IMPLICIT ADDRESSING:
receive (source, message)
IN SEND IN RECEIVE
Possess a value returned when
receive operation performed.
Impossible
way
14
Messages are sent through a queue
that temporarily holds messages.
Merit:
● Greater flexibility
Indirect
Addressing
P P
sender receiver
sends to picks up
15
ONE-TO ONE
● Private communication
● Insulating from other
processes
MANY-TO-ONE
● Client-server interactions
● Mailbox is also called port
ONE-TO-MANY
● broadcasting MANY-TO-MANY
● N servers providing services
to M clients
Relationship
types
Process-Mailbox
Association
16
• Ports are statically associated with a process
• Ports are created and permanently assigned
to processes
e.g., ONE-TO-ONE relationship
• When many senders are associated
dynamically.
• connect and disconnect primitives used
here.
STATIC DYNAMIC
Process Ownership
of Mailbox
17
• Mailbox is created and owned by receiving
process
• When process (receiver) destroyed, port also
destroyed
• OS creates mailboxes.
• ownership is of creating processes.
• These mailboxes terminate with process.
• OS may terminate them explicitly
PORT OTHERS
4.
Message Format
There are two approaches of message
format
1. Fixed-length message
2. Variable-length message
Short length messages are preferred in some
operating system.
It is used to minimize processing and storage
overhead.
If large amount of data is required to be passed in
fixed-length messages, the data is placed in a file
and the messages references that file.
Fixed-length
message
02
03
01
Variable-length
message
20
Messages that do not have fixed length. The
length depends on how large the message is.
It consists of a header and a body.
Header contains the information about the
message ie type, id and etc.
There can be additional information such as
pointer, sequence number, priority field.
Body contains the message that is to be passed.
5.
Queuing Discipline
The order through which messages
are received by the receiver.
Queue is a repository of messages, and these messages are managed in First-in
First-out manner (FIFO). Messages are stored in queues and the messages that
are sent first are received first.
Alternative is to permit receiver to choose which message to receive next after
inspecting the message queue.
Another alternative is to receive messages according to their priority. Some
messages like error message are urgent and should to be received first, for this
reason messages are assigned priorities using a priority band. Ordinary
messages have a priority of zero. High-priority messages are high priority by
nature of their message type or designation by sender.
Alternative Approaches
02
03
01
23
6.
Mutual
Exclusion
Mutual exclusion is a property of process
synchronization which states that “no two
processes can exist in the critical section
at any given point of time”
24
● Only one process at a time is allowed in
the critical section for a resource.
● no deadlock or no starvation.
● A process that halts in its Non-critical
section must do so without interfering
with the processes.
● A process must not be delayed access
to a critical section when there is no
other process using it.
● A process remains inside its critical
section for a finite time only.
Requirements
For Mutual
Exclusion
> Critical Section is the part of a
program which tries to access shared
resources
Assume the use of the blocking receive primitive
and the nonblocking send primitive
A set of concurrent processes share a mailbox, box,
which can be used by all processes to send and
receive
The mailbox is initialized to contain a single
message with null content
Way to
enforce
Mutual
exclusion
02
03
01
A process wishing to enter its critical section first
attempts to receive a message
If the mailbox is empty, then the process is
blocked.
Once a process has acquired the message, it
performs its critical section and then places the
message back into the mailbox
Way to
enforce
Mutual
exclusion
05
06
04
27
This solution assumes that if more than one
process performs the receive operation
concurrently, then:
• If there is a message, it is delivered to only
one process and the others are blocked, or
• If the message queue is empty, all processes
are blocked; when a message is available, only
one blocked process is activated and given the
message.
These assumptions are true of virtually all
message-passing facilities.
University
of
Karachi
|
Dept
of
Computer
Science
Thanks!
Does anyone have any questions?

Message Passing Systems

  • 1.
  • 2.
    Topics: Synchronization Addressing Message Format Queueing Discipline MutualExclusion B19103008 Amaim Shaikh ______________ Message Format And Queueing Discipline B19103019 Hareem Saad ______________ Synchronization B19103047 Neha Haroon ______________ Addressing B19103065 Syeda Sughra Raza ______________ Mutual Exclusion
  • 3.
    1. Message Passing Message passing isa technique for invoking behavior (i.e., running a program) on a computer.
  • 4.
    4 Message passing isthe sharing of data by sending and receiving messages between the processes. Message passing satisfies the requirements of interaction between processes i.e., synchronization and communication. Moreover, mutual exclusion can only be carried out if processes are synchronized. Physical implementation ● Single processor system ● Multiprocessor system ● Distributed system
  • 5.
    The two operations of messagepassing 5 It's the method used by a process to send a message to another process The syntax is Send (destination, message) It's the method used by a process to receive a message by another process The syntax is Receive (source, message) Send Receive
  • 6.
    2. Synchronization Process Synchronization isa way to coordinate processes that use shared data.
  • 7.
    What Happens toa process after it issues a send primitive? 7 If the process resumes its work after sending a message i.e. does not wait till the destination process has received the message If the process does not resumes its work after sending a message i.e. it waits till the destination process has received the message Non-blocking Send Blocking send
  • 8.
    What Happens toa process after it issues a receive primitive? 8 If the process performs its work even if no message has been received i.e. it does not wait till the it has received the message to start work if a valid message exists it issues it otherwise it issues a null message If the process cannot perform its work until after the message is received i.e. it waits till it has received the message to start working Non-blocking receive Blocking receive
  • 9.
    In any systemthree combinations of the above primitives may occur 9 Blocking send, blocking receive Both the sender and receiver are blocked until the message has been delivered It is sometimes referred to as a rendezvous Allows tight synchronization sender continues on, while the receiver is blocked until the requested message arrives It allows a process to send one or more messages to a variety of destinations as quickly as possible A process that must receive a message before it can do useful work needs to be blocked until such a message arrives Non-blocking send, non-blocking receive Neither party is required to wait Non-blocking send, blocking receive
  • 10.
    EXAMPLE A process requestsprinting, it send the a message to issue the request in the form of a message and then carry on DANGER Due to the absence of blocking an error could lead to a situation in which a process repeatedly generates messages. Which would consume system resources, including processor time and buffer space. SOLUTION The non-blocking send places the burden on the programmer to determine that a message has been received: Processes must employ reply messages to acknowledge receipt of a message. Non-blocking send 02 03 01
  • 11.
    EXAMPLE A process requestsprinting, it send the a message to issue the request in the form of a message and then carry on DANGER If a message is lost, which can happen in a distributed system, or if a process fails before it sends an anticipated message, a receiving process could be blocked indefinitely. SOLUTION We can use a non-blocking receive to avoid the problem, but in that approach if the message has been sent after the receiving process has been executed the message will be lost forever. Other possible approaches are to allow a process to test whether a message is waiting before issuing a receive and allow a process to specify more than one source in a receive primitive. The latter approach is useful if a process is waiting for messages from more than one source and can proceed if any of these messages arrive. Blocking Receive 02 03 01
  • 12.
    3. Addressing Way of specifying: In send primitive: who is to receive the message In receiver primitive: who is source for message TYPES : 1. Direct Addressing 2. Indirect Addressing ? ? ? ?
  • 13.
    Direct Addressing 13 Includes a specificidentifier of destination process Send (destination, message) Includes a source process (receiver must know ahead of time which process to expect as a source) IMPLICIT ADDRESSING: receive (source, message) IN SEND IN RECEIVE Possess a value returned when receive operation performed. Impossible way
  • 14.
    14 Messages are sentthrough a queue that temporarily holds messages. Merit: ● Greater flexibility Indirect Addressing P P sender receiver sends to picks up
  • 15.
    15 ONE-TO ONE ● Privatecommunication ● Insulating from other processes MANY-TO-ONE ● Client-server interactions ● Mailbox is also called port ONE-TO-MANY ● broadcasting MANY-TO-MANY ● N servers providing services to M clients Relationship types
  • 16.
    Process-Mailbox Association 16 • Ports arestatically associated with a process • Ports are created and permanently assigned to processes e.g., ONE-TO-ONE relationship • When many senders are associated dynamically. • connect and disconnect primitives used here. STATIC DYNAMIC
  • 17.
    Process Ownership of Mailbox 17 •Mailbox is created and owned by receiving process • When process (receiver) destroyed, port also destroyed • OS creates mailboxes. • ownership is of creating processes. • These mailboxes terminate with process. • OS may terminate them explicitly PORT OTHERS
  • 18.
    4. Message Format There aretwo approaches of message format 1. Fixed-length message 2. Variable-length message
  • 19.
    Short length messagesare preferred in some operating system. It is used to minimize processing and storage overhead. If large amount of data is required to be passed in fixed-length messages, the data is placed in a file and the messages references that file. Fixed-length message 02 03 01
  • 20.
    Variable-length message 20 Messages that donot have fixed length. The length depends on how large the message is. It consists of a header and a body. Header contains the information about the message ie type, id and etc. There can be additional information such as pointer, sequence number, priority field. Body contains the message that is to be passed.
  • 21.
    5. Queuing Discipline The orderthrough which messages are received by the receiver.
  • 22.
    Queue is arepository of messages, and these messages are managed in First-in First-out manner (FIFO). Messages are stored in queues and the messages that are sent first are received first. Alternative is to permit receiver to choose which message to receive next after inspecting the message queue. Another alternative is to receive messages according to their priority. Some messages like error message are urgent and should to be received first, for this reason messages are assigned priorities using a priority band. Ordinary messages have a priority of zero. High-priority messages are high priority by nature of their message type or designation by sender. Alternative Approaches 02 03 01
  • 23.
    23 6. Mutual Exclusion Mutual exclusion isa property of process synchronization which states that “no two processes can exist in the critical section at any given point of time”
  • 24.
    24 ● Only oneprocess at a time is allowed in the critical section for a resource. ● no deadlock or no starvation. ● A process that halts in its Non-critical section must do so without interfering with the processes. ● A process must not be delayed access to a critical section when there is no other process using it. ● A process remains inside its critical section for a finite time only. Requirements For Mutual Exclusion > Critical Section is the part of a program which tries to access shared resources
  • 25.
    Assume the useof the blocking receive primitive and the nonblocking send primitive A set of concurrent processes share a mailbox, box, which can be used by all processes to send and receive The mailbox is initialized to contain a single message with null content Way to enforce Mutual exclusion 02 03 01
  • 26.
    A process wishingto enter its critical section first attempts to receive a message If the mailbox is empty, then the process is blocked. Once a process has acquired the message, it performs its critical section and then places the message back into the mailbox Way to enforce Mutual exclusion 05 06 04
  • 27.
    27 This solution assumesthat if more than one process performs the receive operation concurrently, then: • If there is a message, it is delivered to only one process and the others are blocked, or • If the message queue is empty, all processes are blocked; when a message is available, only one blocked process is activated and given the message. These assumptions are true of virtually all message-passing facilities.
  • 28.