Lecture
Lecture
W ilm a 's D u m b T e r m in a l
B e v 's D u m b T e r m in a l
N e llie 's D u m b T e r m in a l
C la r e n c e 's D u m b T e r m in a l
L in e P r in te r
M a in f r a m e
Sneaker Net
M odem
V ic k i's P C
P r in t e r S k ip 's P C H e a t h e r 's P C
Fax
M in ic o m p u te r
S k ip , V ic k i h e r e .
C an I com e dow n
and use your
p r in t e r ?
Modern Network
PC
W o r k s t a t io n
P r in te r
P r in t S e r v e r
W o r k s t a t io n
P r in t e r
L a p to p
W o r k s t a t io n
W o r k s t a t io n
M a in f r a m e
M in ic o m p u t e r
W o r k s t a t io n P r in t e r
W o r k s ta t io n
C it y
Problem Space
• Problem 1
– You have 1 hour to peel 1000 potatoes
– You have 10 people available
• Problem 2
– You have 1 hour to do the dishes after a dinner for
1000 guests
– You have 10 people available
• Problem 3
– You have 1 hour to lay the brick around a 5’ square
dog house
– You have 10 people available
Facilitating Division of Labor:
Work and Communication
• Single Machine Inter-process Communication
– (Signals)
– Pipes (named and unnamed)
– System V and POSIX IPC
• Multiple Machine Inter-process Communication
– Sockets
– Remote Procedure Calls (Sun ONC, OSF DCE, Xerox
Courier (4.3BSD))
– Distributed Shared Memory (Berkeley mmap)
• Single Machine Division of Labor:
– Processes
– Threads
Methods of Solution Distribution:
Input Distribution (Division of Labor)
• Workload Decomposition
– Potato Peelers aboard the USS Enterprise
• loosely coupled (little coordination)
– Roofers or Bricklayers
• tightly coupled (high coordination)
• Software: large database query of all records with a given
characteristic
– Strategy: Divide and Conquer
– Key: Exact same code is operating on different sets of input data
• Software: large matrix multiplication
– Strategy: Divide and Conquer
– Key: Exact same code is operating on different parts of the
matrices
Methods of Solution Distribution:
Process Decomposition (Inter-process
Communication)
• Divide not the work, but the process of conducting the work
– Factory Production Line:
• Identical widgets are coming along the converyor belt, but
several things have to be done to each widget
– Dish Washing Example
• collector, washer, dryer, cabinet deployer
• multiple washers and dryers can be employed (using Input
Distribution)
• Software: A Trade Clearing System
– Each trade must be entered, validated, reported, notified
– Each task can run within a different process on a different
processor
– Strategy: divide the work to be done for each trade into separate
processes, thus increasing overall system throughput
Problems in Distributed
Solutions
• Data access must be synchronized among
multiple processes
• Multiple processes must be able to communicate
among themselves in order to coordinate
activities
• Multiple coordinating processes must be able to
locate one another
Interprocess Communication and
Synchronization using
System V IPC
Message Queues
Shared Memory
Semaphores
System V IPC
• System V IPC was first introduced in SVR2, but
is available now in most versions of unix
• Message Queues represent linked lists of
messages, which can be written to and read from
• Shared memory allows two or more processes to
share a region of memory, so that they may each
read from and write to that memory region
• Semaphores synchronize access to shared
resources by providing synchronized access
among multiple processes trying to access those
critical resources.
Message Queues
• A Message Queue is a linked list of message
structures stored inside the kernel’s memory
space and accessible by multiple processes
• Synchronization is provided automatically by the
kernel
• New messages are added at the end of the queue
• Each message structure has a long message type
• Messages may be obtained from the queue either
in a FIFO manner (default) or by requesting a
specific type of message (based on message type)
Message Structs
• Each message structure must start with a
long message type:
struct mymsg {
long msg_type;
char mytext[512]; /* rest of message */
int somethingelse;
float dollarval;
};
Message Queue Limits
• Each message queue is limited in terms of both
the maximum number of messages it can contain
and the maximum number of bytes it may contain
• New messages cannot be added if either limit is
hit (new writes will normally block)
• On linux, these limits are defined as (in
/usr/include/linux/msg.h):
– MSGMAX 8192 /*total number of messages */
– MSBMNB 16384 /* max bytes in a queue */
Obtaining a Message Queue
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int msgget(key_t key, int msgflg);
• The key parameter is either a non-zero identifier for the
queue to be created or the value IPC_PRIVATE, which
guarantees that a new queue is created.
• The msgflg parameter is the read-write permissions for
the queue OR’d with one of two flags:
– IPC_CREAT will create a new queue or return an
existing one
– IPC_EXCL added will force the creation of a new
queue, or return an error
Writing to a Message Queue
int msgsnd(int msqid, const void * msg_ptr,
size_t msg_size, int msgflags);
ci,j = ∑ai,kbk,j
k=1