Process Synchronization Flashcards
Cooperating Process
A process that can affect or be affected by other executing process. Done by accessing the data section and shared memory.
Race condition
Several process try to access and manilpuate the same data concurrently.
Critical Section solution 3 requirements
- Mutual exclusion: only one process executes the critical section at a given time.
- Progress: there should be progress, if a process needs to enter the cirital section and it can, then it should.
- Bounded waiting: There should be a limit on how much a process needs to wait before being granted permission to enter.
Nonepreemptive kernel
A process running in kernel mode is not allowed to be preempted, insuring no race conditions happen on kernel data structures.
Preemptive kernel
Processes running in kernel mode are allowed to be preemted. The kernel needs to be carefully designed to prevent race conditions. Better since it is more responsive and doesn;t let the kernel hog the system.
Peterson’s Solution
Shared data:
int turn;
boolean flag[N]; Indicates if a process is ready to enter.
Flow for proecess i:
flag[i] = TRUE;
turn=j;
while ( flag[j] & turn == j);
CRITICAL SECTION
flag[i] = FALSE;
REMAINDER SECTION
Atomic operation
Sequence of instructions that must run inorder and with no interference.
TestAndSet
boolean TestAndset (boolean *target)
{
boolean rv = *target;
*target = TRUE;
return rv:
}
void Swap (boolean *a, boolean *b)
{
boolean temp = *a;
a=b;
*b= temp;
}
Semaphore
Basically an integer that is used to solve the mutual problem.
accessed through two atomic operations:
wait(s){
while s <= 0;
; //no op
s–;
}
signal(s){
s++;
}
Binary semphore
Basically a mitex lock, a semaphore that is only 0 or 1.
Semaphore busy waiting fix
Define semaphore as a struct with a value and a process list. If a process needs to wait, it adds itself to the list and blocks itself from continuing execution.
The signal operation removes theprocess from the list and wakes it up (moving it from waiting to ready).