程序代写 CS 563 Concurrent Programming

CS 563 Concurrent Programming
Lecture 5: Message Passing (2)

Client-Server

Copyright By PowCoder代写 加微信 powcoder

request reply
Two-way interaction pattern

Client-Server
(a) with procedures •client does:
call(args)
•server is:
procedure(formals)

Client-Server
(b) with message passing chan request(…), reply(…)
send request(args)
receive reply(vars)
while(true) {# std server loop
receive request(vars)
send reply(results)

Client-Server
while(true) {# std server loop
receive request(vars)
send reply(results)
send request(args)
receive reply(vars)
(c) with message passing and multiple clients
Suppose there are multiple clients (and one
server). What has to change in (b)?

Client-Server
syntax for creating multiple processes
how processes know who they are

Client-Server (Multiple Operations)

Resource Allocation Using Message Passing

Resource Allocation Using Message Passing

Interacting Peers
Used to share data, combine data, make decisions Exchanging values problem:
There are n processes; each has a value; want every process to learn every value
This type of exchange occurs in many places: n-body simulation, etc.

Centralized

Communication Patterns
Message counts:

Synchronous Message Passing
synch_send name(expr1, …, exprN)
Types and number of fields must match Effect:
Evaluate the expressions and produce a message M Atomically append M to the end of the named channel
➡ sender is blocked until the message is received (synchronous)

Producer Consumer
chan values(int);
process Producer{
int data[n];
process Consumer{
int results[n];
for [i=0 to n-1]{
do some computation;
synch_send values(data[i]);
for [i=0 to n-1]{
values(results[i]);
do some computation;
Advantage: bound on the size of channels
Disadvantage: concurrency is reduced anything else?

chan in1(int), in2(int);
process P1{
int value1=1, value2;
synch_send in2(value1);
receive in1(value2); }}
Disadvantage: more prone to deadlock
process P2{
int value1, value2=2;
synch_send in1(value2);
receive in2(value1);

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com