Module3 Process Synchronization
Module3 Process Synchronization
PROCESS SYNCHRONIZATION
Introduction
• Processes can execute concurrently.
– May be interrupted at any time, partially completing execution.
• Exit Section :The code executed upon leaving the critical section.
do
{
flag[i] = true;
turn = j;
while (flag[j] && turn = = j);
critical section
flag[i] = false;
remainder section
} while (true);
Peterson’s Solution (Cont.)
Types of semaphores :
• Counting semaphore – integer value can range over an unrestricted
domain.
• Binary semaphore – integer value can range only between 0 and 1.
Semaphore Implementation :
• In multiprogramming system , busy waiting wastes CPU cycles that
some other process might be able to use productively. This type of
semaphore is called spin lock i.e process spins waiting for lock.
Semaphore Implementation with no Busy waiting
• With each semaphore there is an associated waiting queue.
• Each entry in a waiting queue has two data items:
– value (of type integer)
– pointer to next record in the list.
• Two operations:
– block – place the process invoking the operation on the
appropriate waiting queue.
– wakeup – remove one of processes in the waiting queue and
place it in the ready queue.
typedef struct{
int value;
struct process *list;
} semaphore;
Implementation with no Busy waiting (Cont.)
wait(semaphore *S) {
S->value--;
if (S->value < 0) {
add this process to S->list;
block();
}
}
signal(semaphore *S) {
S->value++;
if (S->value <= 0) {
remove a process P from S->list;
wakeup(P);
}
}
Monitors
• A high-level abstraction that provides a convenient and effective
mechanism for process synchronization.
monitor monitor-name
{
// shared variable declarations
procedure P1 (…) { …. }
procedure Pn (…) {……}
Initialization code (…) { … }
}
}
Chapter 8
Memory management
Basic Hardware
• Main memory and registers built in to the processor itself are
the only storage that the CPU can access directly.
• If the data are not in memory they must be moved before CPU
can operate on them.
• Only the operating system can load base and limit registers.
• Worst-fit: Allocate the largest hole; must also search entire list
– Produces the largest leftover hole.