0% found this document useful (0 votes)
1 views16 pages

Cse333 ch3 B

Uploaded by

omerdisneyplus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views16 pages

Cse333 ch3 B

Uploaded by

omerdisneyplus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Cooperating Processes!

■ 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 "
● Computation speed-up"
● Modularity"
● Convenience"

Chapter 3 – Part II ! 1!
Communications Models!

"a. Message Passing " "b. Shared Memory"

Chapter 3 – Part II ! 2!
Producer-Consumer Problem!

■ Paradigm for cooperating processes,


producer process produces information that is
consumed by a consumer process"
● unbounded-buffer places no practical limit on the
size of the buffer"
● bounded-buffer assumes that there is a fixed
buffer size"

Chapter 3 – Part II ! 3!
Bounded-Buffer – Shared-Memory Solution!

■ Shared data"
#define BUFFER_SIZE 10"
typedef struct {"
". . ."
} item;"
"
item buffer[BUFFER_SIZE];"
int in = 0;"
int out = 0;"
■ Solution is correct, but can only use
BUFFER_SIZE-1 elements"
!

Chapter 3 – Part II ! 4!
Bounded-Buffer – Producer Process!

while (true) {
/* Produce an item */
while (((in + 1) %
BUFFER_SIZE) == out)
; /* do nothing -- no
free buffers */
buffer[in] = item;
in = (in + 1) % BUFFER_SIZE;
{
"

Chapter 3 – Part II ! 5!
Bounded Buffer – Consumer Process!

while (true) {
while (in == out)
; // do nothing --
nothing to consume
// remove an item from the
buffer
item = buffer[out];
out = (out + 1) %
BUFFER_SIZE;
}

Chapter 3 – Part II ! 6!
Message Passing System!
■ Mechanism for processes to communicate and to
synchronize their actions"
■ Message system – processes communicate with
each other without resorting to shared variables"
■ IPC facility provides two operations:"
send(message) –message size fixed/variable "

● 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)"

Chapter 3 – Part II ! 7!
Direct Communication!
■ Processes must name each other explicitly:"
● 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"
Chapter 3 – Part II ! 8!
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"
■ 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"
Chapter 3 – Part II ! 9!
Synchronization!
■ Message passing may be either blocking or non-
blocking"
■ Blocking is considered synchronous!
● Blocking send has the sender block until the
message is received"
● Blocking receive has the receiver block until a
message is available"
■ Non-blocking is considered asynchronous!
● Non-blocking send has the sender send the
message and continue"
● Non-blocking receive has the receiver receive a
valid message or null"

Chapter 3 – Part II ! 10!


Client-Server Communication!

■ Sockets"
■ Remote Procedure Calls"

Chapter 3 – Part II ! 11!


Sockets!

■ A socket is defined as an endpoint for


communication"
■ Concatenation of IP address and port"
■ The socket 161.25.19.8:1625 refers to port
1625 on host 161.25.19.8!
■ Communication consists between a pair of
sockets"

Chapter 3 – Part II ! 12!


Socket Communication!

Chapter 3 – Part II ! 13!


Remote Procedure Calls!

■ Remote procedure call (RPC) abstracts procedure


calls between processes on networked systems."
■ Stubs – client-side proxy for the actual procedure
on the server."
■ The client-side stub locates the server and
marshalls the parameters."
■ The server-side stub receives this message,
unpacks the marshalled parameters, and performs
the procedure on the server."

Chapter 3 – Part II ! 14!


Execution of RPC!

Chapter 3 – Part II ! 15!


Marshalling Parameters!

Chapter 3 – Part II ! 16!

You might also like