Beruflich Dokumente
Kultur Dokumente
Processes
OPERATING SYSTEMS
Design and Implementation
Instructor:
Hadi Salimi
Computer Engineering Department
IRAN University of Science and Technology
hsalimi@iust.ac.ir
IPC
Processes frequently need to
communicate with other processes
For example, in a shell pipeline, the output
of the first process must be passed to the
second process.
This is called Inter-Process
Communication or IPC.
Race Conditions
Situations like this are called race
conditions.
What will happen if two processes execute
the following code?
X=0;
…
Read(x);
X++;
Write(x);
Solution Criteria
Conditions to hold to have a good solution:
No two processes may be simultaneously
inside their critical regions.
No assumptions may be made about speeds
or the number of CPUs.
No process running outside its critical section
may block other processes.
No process should have to wait forever to
enter its critical region.
Disabling Interrupts
Let each process to disable all interrupts
just after entering its critical section and
re-enable them just before leaving.
Isit wise to let the processes do such a job?
What will happen if one process never turn
the interrupts on?
What if the program is running on a
multiprocessor?
Strict Alternation
TSL Instruction
It is another proposal that requires a little
help from hardware.
Many computers have a TEST AND LOCK
instruction that works as follows:
Reads the memory into a register and stores
a non-zero value into it.
Producer/Consumer
Semaphores
In many problems there is a need to count
an event, like producing an item or
consuming it.
Accessing to this counter should be
protected against concurrent processes.
Such a protected counter is called a
semaphore which has more features.
Semaphores (cont.)
How to protect a critical section using
semaphores?
int s = 1;
Down(s);
…
Critical Section
…
Up(s);
Producer/Consumer
Monitors (cont.)
To make it easier to write correct
programs, a higher level primitive called
monitor is introduced.
It is a collection of procedures, variables
and data structures that are all grouped in
a package.
An important property:
Only one process can be active in a monitor
at any time.
5/19/2009 Operating Systems - By: Hadi Salimi - IUST-CE 26
Monitors (cont.)
monitor example
int x;
procedure producer(x)
…
end;
procedure consumer(x)
…
end;
5/19/2009 Operating Systems - By: Hadi Salimi - IUST-CE 27
Monitors (cont.)
Monitors are a programming language
construct, so the compiler should handle
calls to procedures.
When a process calls a monitor
procedure, the first few instructions of the
procedure will check to see if any other
process is currently active or not.