Op Sys ppt
-
Upload
rajarajkumar543 -
Category
Documents
-
view
218 -
download
0
Transcript of Op Sys ppt
-
7/30/2019 Op Sys ppt
1/20
Northwestern UniversityDepartment of Computer Science
Fabin E. Bustamante - Fall 2002CS-343 Operating Systems
Cooperating Process
Cooperating Processes
Interprocess Communication (IPC)
Process Synchronization
Critical Section Problem
First Attempts to a Solution
-
7/30/2019 Op Sys ppt
2/20
Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 2
Cooperating Processes
Advantages of process cooperation Information sharing
Computation speed-up
Modularity
Convenience
Independent process cannot affect/be affected by theexecution of another process, cooperating ones can
Issues Communication
Avoid processes getting into each others way
Ensure proper sequencing when there are dependencies
Common paradigm: producer-consumer unbounded-buffer - no practical limit on the size of the buffer
bounded-buffer - assumes fixed buffer size
-
7/30/2019 Op Sys ppt
3/20
Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 3
Interprocess Communication
For communication and synchronization Shared memory
OS provided IPC
Message system no need for shared variable
two operations send(message) message size fixed or variable
receive(message)
If P and Q wish to communicate, they need to establish a communication link between them
exchange messages via send/receiveImplementation of communication link physical (e.g., shared memory, hardware bus)
logical (e.g., logical properties)
-
7/30/2019 Op Sys ppt
4/20
Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 4
Implementation Questions
How are links established?
Can a link be associated with more than two
processes?
How many links can there be between every pair of
communicating processes?
What is the capacity of a link?
Is the size of a message that the link can
accommodate fixed or variable?
Is a link unidirectional or bi-directional?
-
7/30/2019 Op Sys ppt
5/20
Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 5
Naming for Communication
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
-
7/30/2019 Op Sys ppt
6/20
-
7/30/2019 Op Sys ppt
7/20Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 7
Indirect Communication
Operations Create and destroy a mailbox
Send and receive messages through mailbox
Primitives are defined as:send(A, message) send a message to mailbox A
receive(A, message) receive a message from mailbox AMailbox sharing P1, P2, and P3 share mailbox A.
P1, sends; P2 and P3 receive.
Who gets the message?
Solutions Avoid the problem altogether - at most two processes per link
Allow only one process at a time to execute a receive
The system decides and notified the sender
-
7/30/2019 Op Sys ppt
8/20Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 8
Buffering & Synchronization
Buffering queue of messages attached to the link
1. Zero capacity Sender must wait for receiver (rendezvous)
2. Bounded capacity Sender must wait if link full
3. Unbounded capacity Sender never waits
Synchronization
Message passing may be either blocking or non-blocking
Blocking is considered synchronous
Non-blocking is considered asynchronous
Send and receive primitives may be either blocking or non-
blocking
-
7/30/2019 Op Sys ppt
9/20Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 9
Bounded-buffer Producer/Consumer
#define BUFFER_SIZE 10 /* Shared data */
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0, out = 0;
item nextProduced; /* Producer */
while (1) {
while (((in + 1) % BUFFER_SIZE) == out); /* do nothing */
buffer[in] = nextProduced;
in = (in + 1) % BUFFER_SIZE;
}
item nextConsumed; /* Consumer */
while (1) {
while (in == out); /* do nothing */
nextConsumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
}
-
7/30/2019 Op Sys ppt
10/20
-
7/30/2019 Op Sys ppt
11/20
-
7/30/2019 Op Sys ppt
12/20Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 12
Bounded-buffer atomic operations
The statements must be performed atomicallycounter++ counter--
Atomic operation - it completes, in its entirety, without
interruption
Problem look one level down at the machine lang.count++:
register1 = counter
register1 = register1 + 1
counter = register1
count--:register2 = counter
register2 = register2 1
counter = register2
-
7/30/2019 Op Sys ppt
13/20
-
7/30/2019 Op Sys ppt
14/20
-
7/30/2019 Op Sys ppt
15/20Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 15
The Critical-Section Problem
n processes all competing to use some shared data
Each process has a code segment, called critical
section, in which the shared data is accessed
Problem ensure that when one process is executing
in its critical section, no other process is allowed to
execute in its critical section
-
7/30/2019 Op Sys ppt
16/20
-
7/30/2019 Op Sys ppt
17/20
-
7/30/2019 Op Sys ppt
18/20
-
7/30/2019 Op Sys ppt
19/20
Fabin E. Bustamante - Fall 2002 CS-343 Operating Systems 19
Algorithm 2
Shared variables
boolean flag[2]; /* initially flag [0] = flag [1] = false */
flag [i] = true Pi ready to enter its critical section
Process Pido {
flag[i] := true;while (flag[j]) ;
critical section
flag [i] = false;
remainder section} while (1);
Satisfies mutual exclusion, but not progress
-
7/30/2019 Op Sys ppt
20/20