You are on page 1of 9

CASE STUDY 4

CASE STUDIES OF PROCESS


SYNCHRONIZATION
Synchronization of POSIX Threads
Process Synchronization in Unix
Process Synchronization
y in Linux
Process Synchronization in Solaris
Process Synchronization in Windows

6.2
2
SYNCHRONIZATION OF POSIX
THREADS
POSIX threads provide:
• Mutexes for mutual exclusion
• A mutex is a binary semaphore
• Condition variables for control synchronization between
processes

An OS may implement POSIX threads as kernel-level threads


or user-level threads

6.3
3
PROCESS SYNCHRONIZATION
IN UNIX
Unix system V provides a kernel-level implementation of
semaphores
• Name of a semaphore is called a key
• Key
K isi associated
i t d with
ith an array off semaphores
h
• Processes share a semaphore by using the same key

Unix SVR4 keeps track of all operations performed by a process


on each semaphore used by it
• Performs an undo on them when process terminates
• It helps to make programs more reliable

Unix 4.4BSD places a semaphore in shared memory areas and


uses a hybrid implementation

6.4
4
PROCESS SYNCHRONIZATION
IN LINUX
Linux has Unix-like
Unix like semaphore for user processes
Also provides semaphores for use by the kernel:
• Conventional semaphore
p
• Uses efficient kernel-level implementation scheme
• Reader–writer semaphore

Kernels older than 2.6 implemented mutual exclusion in the


kernel space through system calls
2.6 kernel has a fast user space mutex called mutex
• Uses a hybrid implementation
• Provides time-bound
time bound wait operation

6.5
5
PROCESS SYNCHRONIZATION
IN SOLARIS
Interesting features:
• Reader–writer semaphores
• Analogous to the one in Linux
• Adaptive mutexes
• Useful in a multiprocessor OS
• Uses the p
priority
y inheritance p
protocol to reduce synchronization
y
delays
• Data structure called a turnstile
• Holds information concerning
g threads that are blocked on a mutex
or reader–writer semaphore
• Used for synchronization and priority inheritance

6.6
6
PROCESS SYNCHRONIZATION
IN WINDOWS
Dispatcher object is embedded in every object over which
synchronization is needed
• It can be in signaled/non-signaled state
• Dispatcher objects used in process, file, etc. (next slide)

p , queued
Provides spinlock, q spinlock,
p , fast mutex and push
p locks

Vista provides a reader-writer lock

6.7
7
PROCESS SYNCHRONIZATION IN
WINDOWS

6.8
8
SUMMARY
Process synchronization is a generic term for data access synchronization
and control synchronization

A race condition occurs when actions of concurrent p


processes may
y have
unexpected consequences
• Avoided through mutual exclusion

A id
Avoidance off race conditions
diti is
i a primary
i issue
i in
i process synchronization
h i ti

Critical section: section of code that accesses some shared data in a


m t all exclusive
mutually e cl si e manner

Synchronization achieved through: indivisible instructions, semaphores,


monitors

6.9
9

You might also like