30.9.21
 Process Synchronization is a way to
coordinate processes that use shared data.
 It occurs in an operating system among
cooperating processes.
10/1/2021 2
Dr.M.Karthika/AP/IT/MTNC
 The main purpose of synchronization is the
sharing of resources without interference
using mutual exclusion.
 The other purpose is the coordination of the
process interactions in an operating system.
Semaphores and monitors are the most
powerful and most commonly used
mechanisms to solve synchronization
problems.
10/1/2021 3
Dr.M.Karthika/AP/IT/MTNC
 It is the task phenomenon of coordinating the
execution of processes in such a way that no two
processes can have access to the same shared
data and resources.
 It is a procedure that is involved in order to
preserve the appropriate order of execution of
cooperative processes.
 In order to synchronize the processes, there are
various synchronization mechanisms.
 Process Synchronization is mainly needed in a
multi-process system when multiple processes
are running together, and more than one
processes try to gain access to the same shared
resource or any data at the same time.
10/1/2021 4
Dr.M.Karthika/AP/IT/MTNC
 Many systems provide hardware support for critical section code.
The critical section problem could be solved easily in a single-
processor environment if we could disallow interrupts to occur
while a shared variable or resource is being modified.
 In this manner, we could be sure that the current sequence of
instructions would be allowed to execute in order without pre-
emption. Unfortunately, this solution is not feasible in a
multiprocessor environment.
 Disabling interrupt on a multiprocessor environment can be
time-consuming as the message is passed to all the processors.
 This message transmission lag delays the entry of threads into
the critical section, and the system efficiency decreases.
10/1/2021 5
Dr.M.Karthika/AP/IT/MTNC
 As the synchronization hardware solution is
not easy to implement for everyone, a strict
software approach called Mutex Locks was
introduced.
 In this approach, in the entry section of code, a
LOCK is acquired over the critical resources
modified and used inside the critical section,
and in the exit section that LOCK is released.
 As the resource is locked while a process
executes its critical section hence no other
process can access it.
10/1/2021 6
Dr.M.Karthika/AP/IT/MTNC
 Solaris 2
 Windows 2000
10/1/2021 7
Dr.M.Karthika/AP/IT/MTNC
 Solaris implements variety of locks to support
multitasking, multithreading and
multiprocessing.
 It uses adaptive mutexes, conditional variables,
semaphores, read-write locks, turnstiles to
control access to critical sections.
 On A multiprocessor system it starts as a
standard semaphore spin-lock.
 If the lock is held by a thread which is running
on another CPU then the thread spins.
 If the lock is held by a thread which is currently
in run state,the thread blocks, going to sleep
until it is awakened by the signal of releasing the
lock.
10/1/2021 8
Dr.M.Karthika/AP/IT/MTNC
 The spin-waiting method is exceedingly
inefficient if code segment is longer.
So conditional variables, semaphores are
used for them.
 Solaris provides Read-Write lock to protect
the data are frequently accessed by long
section of code usually in read-only manner.
 It uses turnstiles to order the list of threads
waiting to acquire either an adaptive mutex
or read-writer lock.
10/1/2021 9
Dr.M.Karthika/AP/IT/MTNC
 Turnstile is a queue structure containing
threads blocked on a lock.
 They are per lock holding thread, not per
object.
 Turnstiles are organized according to
priority-inheritance which gives the running
thread the highest of the priorities of the
threads in its turnstiles to prevent priority
inversion.
10/1/2021 10
Dr.M.Karthika/AP/IT/MTNC
 Locking mechanisms are used by kernel is
also used by user-level threads, so that the
locks are available both inside and outside of
the kernel. The difference is only that
priority-inheritance in only used in kernel,
user-level thread does not provide this
functionality.
 To optimize Solaris performance, developers
refine the locking methods as locks are used
frequently and typically for crucial kernel
functions, tuning their implementations and
use to gain great performance.
10/1/2021 11
Dr.M.Karthika/AP/IT/MTNC
 Windows operating system is a multithreaded
kernel that provide support for real time
application and multiprocessors.
 On uniprocessor system, Windows provides
interrupt masks to protect access to global
resources.
 It protects access to global resource using
spinlock.
 The kernel uses spinlocks only to protect short
code segment like Solaris.
 The kernel ensures that while holding a spinlock,
a thread will never be preempted.
10/1/2021 12
Dr.M.Karthika/AP/IT/MTNC
 Windows provide dispatcher object for thread
synchronization according to several different
mechanisms including mutexes, semaphores,
events and timers.
 The system protects shared data by requiring
a thread to gain ownership of a mutex for
accessing the data and when it is finished,
releases the ownership.
10/1/2021 13
Dr.M.Karthika/AP/IT/MTNC
 Events acts as a conditional variable to notify
a waiting thread when desired condition
occurs.
 Timers are used to notify one or more thread
when time expired.
 Dispatcher objects may be either signaled
state or a non-signaled state.
10/1/2021 14
Dr.M.Karthika/AP/IT/MTNC
10/1/2021 15
Dr.M.Karthika/AP/IT/MTNC
 Signaled state indicates that an object is
available and a thread will not block when
acquiring the object.
 Non-signaled state indicates that an object is
not available and a thread will block when
trying to acquire the object.
10/1/2021 16
Dr.M.Karthika/AP/IT/MTNC
THANK YOU
10/1/2021 17
Dr.M.Karthika/AP/IT/MTNC

Examples in OS synchronization for UG

  • 1.
  • 2.
     Process Synchronizationis a way to coordinate processes that use shared data.  It occurs in an operating system among cooperating processes. 10/1/2021 2 Dr.M.Karthika/AP/IT/MTNC
  • 3.
     The mainpurpose of synchronization is the sharing of resources without interference using mutual exclusion.  The other purpose is the coordination of the process interactions in an operating system. Semaphores and monitors are the most powerful and most commonly used mechanisms to solve synchronization problems. 10/1/2021 3 Dr.M.Karthika/AP/IT/MTNC
  • 4.
     It isthe task phenomenon of coordinating the execution of processes in such a way that no two processes can have access to the same shared data and resources.  It is a procedure that is involved in order to preserve the appropriate order of execution of cooperative processes.  In order to synchronize the processes, there are various synchronization mechanisms.  Process Synchronization is mainly needed in a multi-process system when multiple processes are running together, and more than one processes try to gain access to the same shared resource or any data at the same time. 10/1/2021 4 Dr.M.Karthika/AP/IT/MTNC
  • 5.
     Many systemsprovide hardware support for critical section code. The critical section problem could be solved easily in a single- processor environment if we could disallow interrupts to occur while a shared variable or resource is being modified.  In this manner, we could be sure that the current sequence of instructions would be allowed to execute in order without pre- emption. Unfortunately, this solution is not feasible in a multiprocessor environment.  Disabling interrupt on a multiprocessor environment can be time-consuming as the message is passed to all the processors.  This message transmission lag delays the entry of threads into the critical section, and the system efficiency decreases. 10/1/2021 5 Dr.M.Karthika/AP/IT/MTNC
  • 6.
     As thesynchronization hardware solution is not easy to implement for everyone, a strict software approach called Mutex Locks was introduced.  In this approach, in the entry section of code, a LOCK is acquired over the critical resources modified and used inside the critical section, and in the exit section that LOCK is released.  As the resource is locked while a process executes its critical section hence no other process can access it. 10/1/2021 6 Dr.M.Karthika/AP/IT/MTNC
  • 7.
     Solaris 2 Windows 2000 10/1/2021 7 Dr.M.Karthika/AP/IT/MTNC
  • 8.
     Solaris implementsvariety of locks to support multitasking, multithreading and multiprocessing.  It uses adaptive mutexes, conditional variables, semaphores, read-write locks, turnstiles to control access to critical sections.  On A multiprocessor system it starts as a standard semaphore spin-lock.  If the lock is held by a thread which is running on another CPU then the thread spins.  If the lock is held by a thread which is currently in run state,the thread blocks, going to sleep until it is awakened by the signal of releasing the lock. 10/1/2021 8 Dr.M.Karthika/AP/IT/MTNC
  • 9.
     The spin-waitingmethod is exceedingly inefficient if code segment is longer. So conditional variables, semaphores are used for them.  Solaris provides Read-Write lock to protect the data are frequently accessed by long section of code usually in read-only manner.  It uses turnstiles to order the list of threads waiting to acquire either an adaptive mutex or read-writer lock. 10/1/2021 9 Dr.M.Karthika/AP/IT/MTNC
  • 10.
     Turnstile isa queue structure containing threads blocked on a lock.  They are per lock holding thread, not per object.  Turnstiles are organized according to priority-inheritance which gives the running thread the highest of the priorities of the threads in its turnstiles to prevent priority inversion. 10/1/2021 10 Dr.M.Karthika/AP/IT/MTNC
  • 11.
     Locking mechanismsare used by kernel is also used by user-level threads, so that the locks are available both inside and outside of the kernel. The difference is only that priority-inheritance in only used in kernel, user-level thread does not provide this functionality.  To optimize Solaris performance, developers refine the locking methods as locks are used frequently and typically for crucial kernel functions, tuning their implementations and use to gain great performance. 10/1/2021 11 Dr.M.Karthika/AP/IT/MTNC
  • 12.
     Windows operatingsystem is a multithreaded kernel that provide support for real time application and multiprocessors.  On uniprocessor system, Windows provides interrupt masks to protect access to global resources.  It protects access to global resource using spinlock.  The kernel uses spinlocks only to protect short code segment like Solaris.  The kernel ensures that while holding a spinlock, a thread will never be preempted. 10/1/2021 12 Dr.M.Karthika/AP/IT/MTNC
  • 13.
     Windows providedispatcher object for thread synchronization according to several different mechanisms including mutexes, semaphores, events and timers.  The system protects shared data by requiring a thread to gain ownership of a mutex for accessing the data and when it is finished, releases the ownership. 10/1/2021 13 Dr.M.Karthika/AP/IT/MTNC
  • 14.
     Events actsas a conditional variable to notify a waiting thread when desired condition occurs.  Timers are used to notify one or more thread when time expired.  Dispatcher objects may be either signaled state or a non-signaled state. 10/1/2021 14 Dr.M.Karthika/AP/IT/MTNC
  • 15.
  • 16.
     Signaled stateindicates that an object is available and a thread will not block when acquiring the object.  Non-signaled state indicates that an object is not available and a thread will block when trying to acquire the object. 10/1/2021 16 Dr.M.Karthika/AP/IT/MTNC
  • 17.