Message Passing Models in Computer Science

 
message passing model
 
PRODUCER-CONSUMER
PROBLEM
 
 
Two semaphores
 
empty (i.v. 1)
full (i.v. O)
 
 
{
while (TRUE) {
 
<generate message to put in the
buffer >;
 
P (empty);
 
<put new message in the buffer>;
 
V (full);
     }
}
 
 void producer(void)
 
{
while (TRUE) {
 
P (full);
 
<take
 
one
 
message
 
from
 
the
 
buffer>
 
;
 
V(empty);
 
<consume the message>;
      }
}
 
  void consumer(void)
 
Three semaphores
 
empty (i.v. N)
full (i.v. O)
mutex (i.v. 1)
 
{
 while (TRUE)
{
< generate one message to be put into
 the buffer
 
>;
P (empty);
P (mutex);
<put the new message in the buffer>;
V (mutex);
V(full);}
 
}
 
void producer (void)
 
{
while (TRUE)
{
P (full);
P(mutex);
<take one message from the buffer>;
V(mutex);
V(empty);
<consume the message>;}
}
 
void consumer(void)
 
MESSAGE PASSING MODEL
 
send
 (destination, message)
 
The functions of message
passing are normally
provided in the form of a
couple of primitives:
 
receive
 (source,message)
 
One process 
sends
information in the form
of a message to another
process designated by a
destination
 
A process receives
information by executing
the 
receive 
primitive,
to obtain the 
source
 of
the sending process and
the 
message
 
Design issues of message
systems:
 
Addressing
 
Synchronization
 
Addressing
Direct addressing
 
The
 
send
 
primitive
 
includes
a specific identifier for
the destination process
send (P2, message)
 
 
 
 
 
The 
receive 
can be handled
in one of the two ways:
 
The process 
explicitly
design a sending process:
 
receive (P1, message)
 
 
 
 
 
If it is impossible to
specify in advance the
source process
 
 
 
 
 
implicit addressing
: the
source parameter specifies
a value yelded when the
receive operation has been
performed to indicate the
sender process.
 
 
 
 
 
Indirect addressing
 
Messages are not directly
sent from senders to
receivers
 
 
 
 
 
Messages are sent to
intermedia shared data
structures (mailbox) that
can temporaly hold messages
 
 
 
 
 
The relationship between
senders and receivers can
be:
 
  
one-to-one
  
many-to-one
  
many-to-many
 
 
 
 
 
A 
one-to-one
 relationship
allows
 
private
 
communication
to be set up betweeen a
couple of processes.
 
 
 
 
 
A 
many-to-one
 relationship
is useful for client-server
interaction.
 
The mailbox is often
referred to as a 
port
 
client/server model
 
A 
one-to-many
 
relationship
allows for one sender and
multiple receivers.
 
It is useful for
applications where messages
are to be broadcasted to
groups of reveiver
processes.
 
Message
 
 
 
 
 
SYNCHRONIZATION
 
The communication of a
message between two
processes implies some
level of synchronization
 
 
 
 
 
The receiver cannot receive
a message until it has been
sent by another process
SYNCHRONIZATION
 
 
 
 
 
In addition, we need to
specify what happens to a
process after a send or
receice primitive.
 
 
 
 
 
Message passing may be
either 
blocking or
nonblocking
 (synchronous
or asynchronous)
 
 
 
 
 
Blocking send
: the sending
process is blocked until
the message is received
either by the receiving
process or by the mailbox.
 
 
 
 
 
Nonblocking send: 
the
sending process sends the
message and immediately
resumes operation.
 
 
 
 
 
Blocking receive
: the
receiver blocks until a
message is available.
 
 
 
 
 
Nonblocking receive:
if there is no waiting
message, the process
continues executing,
abandoning the attempt to
receive.
 
 
 
 
 
Rendez vous 
betveen the
sender and the receiver:
both send and receive are
blocked by the operation
 
 
 
 
 
Extended rendezvous
:
the sender is blocked until
the receiver completed the
implied action.
 
 
KERNEL OF A
PROCESS SYSTEM
 
A small set of data
structures and functions
that provide the core
support to any concurrent
program.
 
The role of a kernel
is to provide a virtual
processor to each
process
 
PCBs
process_in_execution
ready-process-queues
semaphores and blocked-
process-queues
 
Kernel data structures
 
Context switch management:
save and restore the PCBs
of the processes.
 
Kernel functions
 
Decision of the ready
process to which assign
the CPU.
Kernel functions
 
Interrupt handling
Operations on processes
(system calls)
 
The kernel starts
executing when
an interrupt occurs
 
External interrupts
 
from
peripheral devices
 
Internal interrupts or
traps
 
triggered by the
executing process
 
A 
stack
 is associated to
any process
 
Example
 
Double set of general
registers R1, R2, …, Rn
and R’1, R’2, …, R’n and
two registers SP and SP’
(user and kernel)
Example
Slide Note
Embed
Share

Message passing models in computer science involve concepts like producer-consumer problems, semaphores, and buffer management. This content explores various scenarios such as void producers and consumers, as well as the use of multiple semaphores. The functions of message passing are detailed, highlighting how processes communicate through messages.

  • Message Passing
  • Computer Science
  • Producer-Consumer
  • Semaphores
  • Buffer Management

Uploaded on Sep 15, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. message passing model

  2. PRODUCER-CONSUMER PROBLEM buffer producer consumer

  3. Two semaphores empty (i.v. 1) full (i.v. O)

  4. void producer(void) { while (TRUE) { <generate message to put in the buffer >; P (empty); <put new message in the buffer>; V (full); } }

  5. void consumer(void) { while (TRUE) { P (full); <takeonemessagefromthebuffer>; V(empty); <consume the message>; } }

  6. buffer producer consumer

  7. Three semaphores empty (i.v. N) full (i.v. O) mutex (i.v. 1)

  8. void producer (void) { while (TRUE) {< generate one message to be put into the buffer >; P (empty); P (mutex); <put the new message in the buffer>; V (mutex); V(full);} }

  9. void consumer(void) {while (TRUE) {P (full); P(mutex); <take one message from the buffer>; V(mutex); V(empty); <consume the message>;} }

  10. MESSAGE PASSING MODEL

  11. The functions of message passing are normally provided in the form of a couple of primitives: send (destination, message) receive (source,message)

  12. One process sends information in the form of a message to another process designated by a destination

  13. A process receives information by executing the receive primitive, to obtain the source of the sending process and the message

  14. Design issues of message systems: Addressing Synchronization

  15. Addressing Direct addressing Thesendprimitiveincludes a specific identifier for the destination process send (P2, message)

  16. The receive can be handled in one of the two ways: The process explicitly design a sending process: receive (P1, message)

  17. If it is impossible to specify in advance the source process

  18. implicit addressing: the source parameter specifies a value yelded when the receive operation has been performed to indicate the sender process.

  19. Indirect addressing Messages are not directly sent from senders to receivers

  20. Messages are sent to intermedia shared data structures (mailbox) that can temporaly hold messages

  21. The relationship between senders and receivers can be: one-to-one many-to-one many-to-many

  22. A one-to-one relationship allowsprivatecommunication to be set up betweeen a couple of processes.

  23. A many-to-one relationship is useful for client-server interaction. The mailbox is often referred to as a port

  24. client/server model P1 server R port Pn client

  25. A one-to-many relationship allows for one sender and multiple receivers.

  26. It is useful for applications where messages are to be broadcasted to groups of reveiver processes.

  27. Message message type origin e destination ID header source ID message length control information body message contents

  28. SYNCHRONIZATION The communication of a message between two processes implies some level of synchronization

  29. SYNCHRONIZATION The receiver cannot receive a message until it has been sent by another process

  30. In addition, we need to specify what happens to a process after a send or receice primitive.

  31. Message passing may be either blocking or nonblocking (synchronous or asynchronous)

  32. Blocking send: the sending process is blocked until the message is received either by the receiving process or by the mailbox.

  33. Nonblocking send: the sending process sends the message and immediately resumes operation.

  34. Blocking receive: the receiver blocks until a message is available.

  35. Nonblocking receive: if there is no waiting message, the process continues executing, abandoning the attempt to receive.

  36. Rendez vous betveen the sender and the receiver: both send and receive are blocked by the operation

  37. Extended rendezvous: the sender is blocked until the receiver completed the implied action.

  38. KERNEL OF A PROCESS SYSTEM

  39. A small set of data structures and functions that provide the core support to any concurrent program.

  40. The role of a kernel is to provide a virtual processor to each process

  41. Kernel data structures PCBs process_in_execution ready-process-queues semaphores and blocked- process-queues

  42. Kernel functions Context switch management: save and restore the PCBs of the processes.

  43. Kernel functions Decision of the ready process to which assign the CPU.

  44. Interrupt handling Operations on processes (system calls)

  45. The kernel starts executing when an interrupt occurs External interrupts from peripheral devices

  46. Internal interrupts or traps triggered by the executing process

  47. Example A stack is associated to any process

  48. Example Double set of general registers R1, R2, , Rn and R 1, R 2, , R n and two registers SP and SP (user and kernel)

  49. P PCB P stack kernel stack SP R1 1 SP Rn n R1 Process-in- execution Rn g PC value of the process that g PC value of the process that executed the executed the SVC SVC d PS value of the process that d PS value of the process that executed the executed the SVC SVC interrupt handler address interrupt handler address z kernel PSW z kernel PSW PC PS

  50. P PCB P PCB kernel stack 1 1 n n P stack P stack SP R1 SP 1 R1 Rn n Rn PC Process- in -execution iret address Kernel PSW PS

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#