Anda di halaman 1dari 29

Project 1

Deadline
Guarantee
Ratio = 94%
COMP7500 Advanced Operating Systems - 1
COMP7500
Advanced Operating Systems

Message-Passing Systems

Dr. Xiao Qin


Auburn University
http://www.eng.auburn.edu/~xqin
xqin@auburn.edu

COMP7500 Advanced Operating Systems - 2


Review: The producer process.

item next_produced; Buffer is full


while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out )
; /* do nothing */
buffer[in] = next_produced; Go to the next
in = (in + 1) % BUFFER_SIZE; empty buffer slot
}
COMP7500 Advanced Operating Systems - 3
Exercise 7: Please complete the following
code for the consumer process.
item next_consumed; Buffer is empty
while (true) {
while (in == out )
; /* do nothing */
next_consumed = buffer[out]; Go to the next
out = (out + 1) % BUFFER_SIZE; buffer slot

/* consume the item in next consumed */


}

COMP7500 Advanced Operating Systems - 4


Exercise 8 (Plickers): What issue hasn’t been
addressed in the above producer-consumer
solution?
A) No issue. It is a perfect solution.
B) There a debugging problem
C) There is a synchronization problem
D) There is a user-space problem

COMP7500 Advanced Operating Systems - 5


Review: IPC Model - Shared Memory
• An area of memory shared among the
processes that wish to communicate

• The communication is under the control of


the users processes not the operating
system.

• Major issues: To synchronize actions when


shared memory are accessed.

COMP7500 Advanced Operating Systems - 6


Message passing is a mechanism for
processes to communicate and to
synchronize their actions

COMP7500 Advanced Operating Systems - 7


Processes communicate with
each other without resorting
to shared variables

Photo courtesy of Enjoy Life Foods


COMP7500 Advanced Operating Systems - 8
Exercise 1: What are the basic two operations
of a message passing system?

COMP7500 Advanced Operating Systems - 9


send(message)
Photo courtesy of dearfutureme.org
COMP7500 Advanced Operating Systems - 10
receive(message)

Photo courtesy of wvmetronews


COMP7500 Advanced Operating Systems - 11
If processes P and Q wish to communicate

Establish a communication
link between them

Exchange messages via


send/receive

COMP7500 Advanced Operating Systems - 12


Direct Communication

Processes must name


each other explicitly

Exercise 2: Please extend the following prototypes.


send(message)
receive(message)

COMP7500 Advanced Operating Systems - 13


Implementation of Communication Links for
Message Passing

Message Passing on Shared-Memory Systems


COMP7500 Advanced Operating Systems - 14
Implementation of Communication Links for
Message Passing

Message Passing on Shared-Memory Systems


COMP7500 Advanced Operating Systems - 15
Implementation of Communication Links for
Message Passing

Message Passing on Distributed-Memory Systems


COMP7500 Advanced Operating Systems - 16
Exercise 3 (Plickers): Suppose you have implemented message
passing on a shared-memory system and a distributed-memory
system. Which system is more scalable? Why?

A) Shared-Memory System B) Distributed-Memory System


C) They are equally scalable D) Scalability can’t be measured

COMP7500 Advanced Operating Systems - 17


Implementation Issues
• How are links established?
I

• Can a link be associated with more than two


2 processes?

• Is the size of a message fixed or variable?


3

• Is a link unidirectional or bi-directional?


4

• How many links between a pair of processes?


5

COMP7500 Advanced Operating Systems - 18


Exercise 4 (Plickers): How should communicating
processes be associated with a link in direct
communication? Why?
A) A link is associated with multiple pairs of processes
B) A link is associated with exactly one pair of processes
C) A link should be associated with any pair of processes
D) A link is associated with a group of more than two
processes
COMP7500 Advanced Operating Systems - 19
Exercise 5 (Plickers): Is a link unidirectional or
bi-directional in direct communication? Why?
A) A link is unidirectional
B) A link is bidirectional
C) A link is neither unidirectional nor bidirectional
D) A link has a hybrid mode: either unidirectional or
bidirectional

COMP7500 Advanced Operating Systems - 20


The Design of Direct Communication
• Links are established automatically
1

• A link is associated with exactly one pair of processes


2

• Between each pair there exists exactly one link


3

• The link may be unidirectional, but is usually bi-


4 directional

COMP7500 Advanced Operating Systems - 21


Indirect Communication
Messages are directed and
received from mailboxes (also
referred to as ports)

Each mailbox has a unique id


Processes can communicate
only if they share a mailbox

COMP7500 Advanced Operating Systems - 22


Exercise 6 (Plickers): How should communicating
processes be associated with a link in indirect
communication?
A) A link is associated with multiple pairs of processes
B) A link must only be associated with exactly one pair of
processes
C) No link should be associated with communicating processes
D) A link is associated with a group of two or more processes

COMP7500 Advanced Operating Systems - 23


Exercise 7 (Plickers): How many
communication links should each pair of
processes share?
A) Each pair of processes may share several communication
links
B) Each pair of processes must share a single communication
links
C) Each pair of processes must share two communication links
D) Each pair of processes must share three communication links
COMP7500 Advanced Operating Systems - 24
The Design of Indirect Communication
• Link established only if processes share a common mailbox
1

• A link may be associated with many processes


2

• Each pair of processes may share several communication


3 links

• Link may be unidirectional or bi-directional


4

COMP7500 Advanced Operating Systems - 25


Exercise 8: What are the four basic
operations for indirect communication?

• Create a new mailbox (port)


• Send messages through mailbox
• Receive messages through mailbox
• Destroy a mailbox

COMP7500 Advanced Operating Systems - 26


Exercise 9: Please design the prototypes for
the following two operations for indirect
communication.
Send( );

Receive( );

COMP7500 Advanced Operating Systems - 27


Exercise 10: Mailbox Sharing
• P1, P2, and P3 share mailbox A
• P1, sends; P2 and P3 receive

Who gets the message?

• Allow a link to be associated with at most two processes


• Allow only one process at a time to execute a receive operation
• Allow the system to select arbitrarily the receiver. Sender is
notified who the receiver was.
COMP7500 Advanced Operating Systems - 28
Summary: IPC Model – Message Passing

• What are the two operations?

• What are direct and indirect


communications?

• What are implementation issues?

COMP7500 Advanced Operating Systems - 29

Anda mungkin juga menyukai