You are on page 1of 9

Rajasthan Technical University, Kota

Department of Computer Science & Engineering

Subject- Operating System


Course Instructor: Vikas Jain

20/05/2021 1
Type of Process

• Process is categorized into two types on the basis of synchronization:


 
• Independent Processes

• Two processes are said to be independent if the execution of one process does not
affect the execution of another process.

• Cooperative Processes

• Two processes are said to be cooperative if the execution of one process affects the
execution of another process.
• These processes need to be synchronized so that the order of execution can be
guaranteed and consistent.
20/05/2021 2
Why Synchronization

• Processes can execute concurrently:


• May be interrupted at any time, partially completing execution.
• Concurrent access to shared data may result in data inconsistency.

• Need of Synchronization

• When multiple processes execute concurrently sharing some system resources.


• To avoid the inconsistent results.

20/05/2021 3
Race Condition

• When more than one processes are executing the same code or accessing the
same memory or any shared variable in that condition there is a possibility that
the output or the value of the shared variable is wrong so for that all the
processes doing the race to say that my output is correct this condition known as
a race condition.

• A race condition is a situation that may occur inside a critical section.

• Race conditions in critical sections can be avoided using synchronization between


various processes present in the system for its execution

20/05/2021 4
Critical Section

• A section of code, common to n cooperating processes, in which the processes


may be accessing common variables/Resource/code.

• A Critical Section Environment contains:


• Entry Section Code requesting entry into the critical section.
• Critical Section Code in which only one process can execute at any one time. All
the shared variables or resources are placed in the critical section that can lead to
data inconsistency.
• Exit Section The end of the critical section, releasing or allowing others in.
• Remainder Section Rest of the code AFTER the critical section.

20/05/2021 5
20/05/2021 6
Requirements of Synchronization mechanisms
• Mutual Exclusion: If a process is in the critical section, then other processes shouldn't be
allowed to enter into the critical section at that time.

• Progress: If no process is executing in its critical section and


there exist some processes that wish to enter their critical
section, then any one of these process must be allowed to get into its critical section within
definite time.

• Bounded Waiting: There must be some limit to the number of times a process can go into the
critical section i.e. there must be some upper bound.
• If no upper bound is there then the same process will be allowed to go into the critical section
again and again and other processes will never get a chance to get into the critical section.

• Architectural Neutrality: Solution must be portable.

20/05/2021 7
Synchronization Mechanism
• Lock Variable
• TSL (Test-Set-Lock)
• Turn Variable
• Interested Variable
• Peterson Solution
• Semaphore

20/05/2021 8
Lock Variable

• This is a Software Mechanism implemented in User mode.


• IT can be used for more than two processes.
• No Mutual Exclusion.

20/05/2021 9

You might also like