Professional Documents
Culture Documents
3.55
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Bounded Buffer Consumer
item nextConsumed;
while (true) {
while (in == out)
; /* do nothing -- nothing to consume */
/* remove an item from the buffer */
nextConsumed = buffer[out];
out = (out + 1) % BUFFER SIZE;
return nextConsumed;
}
3.56
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Interprocess Communication Message Passing
! Message Passing provides a mechanism for processes to communicate
and to synchronize their actions without sharing the same address space
! IPC facility provides two operations:
" send(message)
" receive(message)
! If P and Q wish to communicate, they need to:
" establish a communication link between them
" exchange messages via send/receive
! Implementation of communication link
" physical (e.g., shared memory, hardware bus)
" logical (e.g., logical properties)
3.57
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Direct Communication
! Each process that wants to communicate must explicitly name the recipient
or sender of the communication:
" send (P, message) send a message to process P
" receive(Q, message) receive a message from process Q
! Properties of communication link
" Links are established automatically
" A link is associated with exactly one pair of communicating processes
" Between each pair there exists exactly one link
" The link may be unidirectional, but is usually bi-directional
3.58
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Indirect Communication
! Messages are directed and received from mailboxes (also known as
ports in Mach)
! A mailbox can be viewed abstractly as an object into which messages
can be placed by processes and from which messages can be removed
" Each mailbox has a unique id
" Processes can communicate only if they share a mailbox
! Properties of communication link
" Link established only if processes share a common mailbox
" A link may be associated with many processes
" Each pair of processes may share several communication links
" Link may be unidirectional or bi-directional
3.59
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Mailbox
! A mailbox can be owned either by a process or by the operating system.
3.60
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Mailbox owned by a process
! If the mailbox is owned by a process (that is the mailbox is part of the
address space of the process) then we distinguish between the owner
(which can only receive messages through this mailbox) and the user
(which can only send messages to the mailbox)
! Since each mailbox has a unique owner, there can be no confusion about
which process should receive a message sent to this mailbox
! When a process that owns a mailbox terminates, the mailbox dissapears
and any process that subsequently sends a message to this mailbox must
be notied that the mailbox no longer exists.
3.61
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Mailbox owned by the OS
! A mailbox that is owned by the operating system is independent and is not
attached to any particular process. The operaring system must provide a
mechanism that allows a process to do the following operations:
" create a new mailbox
" send and receive messages through mailbox
" destroy a mailbox.
! The process that creates a new mailbox is the initial owner of the mailbox
that can receive messages through this mailbox
! The ownership and receiving privilege may be passed to other processes
through appropriate system calls. This provision could result in multiple
receivers for each mailbox.
3.62
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Indirect Communication
! Primitives are dened as:
send(A, message) send a message to mailbox A
receive(A, message) receive a message from mailbox A
3.63
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Synchronization
! Message passing may be either blocking or non-blocking
! Blocking is considered synchronous
" Blocking send: the sender blocks until the message is
received
" Blocking receive: the receiver blocks until a message is
available
! Non-blocking is considered asynchronous
" Non-blocking send: the sender sends the message and
continues
" Non-blocking receive: the receiver receives a valid message
or null
3.64
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Possible combinations
! blocking send and blocking receive (rendez-vous)
! non blocking send and blocking receive
! non blockind send and non blocking receive.
3.65
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Buffering
! Queue of messages attached to the link; implemented in one of three
ways
1. Zero capacity 0 messages#
Sender must wait for receiver (rendez-vous)
2. Bounded capacity nite length of n messages#
Sender must wait if link full
3. Unbounded capacity innite length
Sender never waits
3.66
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Message queue in UNIX
! A message queue is an ordered list of messages held in the kernel, which
processes can access.
! A process can create a new message queue, or it can connect to an
existing one.
msgrcv()
msgsnd() 7 2 4
d
a
t
a
d
a
t
a
d
a
t
a
message queue
key = 1841
3.67
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Queue Properties
! A queue has a unique key, xed size, ownership, and access modes.
3. a signal is raised.
3.73
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Non-blocking
! IPC_WAIT is set
0 rst message#
3. a signal is raised
3.80
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Non-blocking
! IPC_WAIT is set