0% found this document useful (0 votes)
49 views5 pages

OS Process Synchronisation

Uploaded by

Sourav Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views5 pages

OS Process Synchronisation

Uploaded by

Sourav Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Operating System

Topperworld.in

Process synchronisation

Overview:
• Processes Synchronization or Synchronization is the way by which
processes that share the same memory space are managed in an
operating system.
• It helps maintain the consistency of data by using variables or hardware
so that only one process can make changes to the shared memory at a
time.
• There are various solutions for the same such as semaphores, mutex
locks, synchronization hardware, etc
Process Synchronisation:
• An operating system is software that manages all applications on a
device and basically helps in the smooth functioning of our computer.
• Because of this reason, the operating system has to perform many
tasks, sometimes simultaneously.
• This isn't usually a problem unless these simultaneously occurring
processes use a common resource.
❖ For example, consider a bank that stores the account balance of each
customer in the same database.
• Now suppose you initially have x rupees in your account.
• Now, you take out some amount of money from your bank account,
and at the same time, someone tries to look at the amount of money
stored in your account.
• As you are taking out some money from your account, after the
transaction, the total balance left will be lower than x.
• But, the transaction takes time, and hence the person reads x as your
account balance which leads to inconsistent data.
• If in some way, we could make sure that only one process occurs at a
time, we could ensure consistent data.

©Topperworld
Operating System

✓ In the above image, if Process1 and Process2 happen at the same time,
user 2 will get the wrong account balance as Y because of Process1
being transacted when the balance is X.
✓ Inconsistency of data can occur when various processes share a
common resource in a system which is why there is a need for process
synchronization in the operating system.
Process Synchronization in OS Works?
Let us take a look at why exactly we need Process Synchronization.
❖ For example, If a process1 is trying to read the data present in a
memory location while another process2 is trying to change the data
present at the same location, there is a high chance that the data read
by the process1 will be incorrect.

©Topperworld
Operating System

Let us look at different elements/sections of a program:


• Entry Section: The entry Section decides the entry of a process.
• Critical Section: The Critical section allows and makes sure that only
one process is modifying the shared data.
• Exit Section: The entry of other processes in the shared data after the
execution of one process is handled by the Exit section.
• Remainder Section: The remaining part of the code which is not
categorized as above is contained in the Remainder section.a

Critical Section Problem:


• A critical section is a code segment that can be accessed by only one
process at a time.
• The critical section contains shared variables that need to be
synchronized to maintain the consistency of data variables.
• So the critical section problem means designing a way for cooperative
processes to access shared resources without creating data
inconsistencies.

©Topperworld
Operating System

Solutions to the Critical Section Problem:


Any solution to the critical section problem must satisfy the following
requirements:
✓ Mutual exclusion: When one process is executing in its critical section,
no other process is allowed to execute in its critical section.

✓ Progress: When no process is executing in its critical section, and there


exists a process that wishes to enter its critical section, it should not
have to wait indefinitely to enter it.

✓ Bounded waiting: There must be a bound on the number of times a


process is allowed to execute in its critical section, after another
process has requested to enter its critical section and before that
request is accepted.
Most solutions to the critical section problem utilize locks implemented on
software. The solutions include:
✓ test_and_set: Uses a shared boolean variable lock and the
test_and_set instruction that executes atomically and sets the passed
parameter value to true.
✓ compare_and_swap: Same as test_and_set, except that the passed
parameter value is set to true if it is equal to expected in the parameter
of the compare_and_swap instruction.
✓ Mutex locks: Software method that provides the acquire() and
release() functions that execute atomically.
✓ Semaphores: More sophisticated methods that utilize the wait() and
signal() operations that execute atomically on Semaphore S, which is
an integer variable.
✓ Condition variables: Utilizes a queue of processes that are waiting to
enter the critical section.

©Topperworld
Operating System

The general architecture of these solutions is shown below:

©Topperworld

You might also like