You are on page 1of 4

Chapter 6- Deadlock and Starvation

Deadlock
Deadlock is the permanent blocking a set of processes that either compete for system resources
or communicate with each other.
Starvation: is the problem that occurs when high priority processes keep executing and low
priority processes get blocked for indefinite time.
Two general categories of resources can be distinguished
 Reusable: is one that can be safely used by only one process at a time and is not depleted
by that use.
 Consumable: is one that can be created (produced) and destroyed (consumed).
Typically, there is no limit on the number of consumable resources of a particular type.
When deadlock occurs: if each process holds one resource and requests the other.

Types of deadlock
 Deadlock prevention: deadlocks can be prevented by preveting at least one of the four
required conditions. Mutual excution, hold and wait, no promtion and circular wait.
 Deadlock avoidance: Do not grant a resource request if this allocation might lead to
deadlock.
 Deadlock detection: Grant resource requests when possible, but periodically check for
the presence of deadlock and take action to recover.
 Resource allocation graph: is a directed graph that depicts a state of the system of
resources and processes, with each process and each resource represented by a node.
4 Conditions for Deadlock
 Mutual exclusion: One or more than one resources are non-sharable. Only one process
can use at the time.
 Hold and wait: A process holding at least one resource and waiting other resources.
 No preemption: A resource can’t be taken form a process unless the proces releases the
resource
 Circular wait: A set of processes are waiting for each other in circular form.

Deadlock prevention methods as falling into two classes:


 Indirect method of deadlock prevention: is to prevent the occurrence of one of the four
necessary conditions previously listed.
 Direct method of deadlock prevention: is to prevent the occurrence of a circular wait.
Deadlock avoidance: is used by the operating system in order to check whether the system is in
a safe state or in an unsafe state and in order to avoid the deadlocks, the process must need to tell
the operating system about the maximum number of resources a process can request in order to
complete its execution.
 Process Initiation Denial: Don’t start a process if its demands might lead to deadlock.
 Resource Allocation Denial: Don’t grant an increment resource request to a process if
this allocation might lead to deadlock.
 State: is the current allocation of resource to process.
 Safe state: is at least one sequence that doesn’t result in deadlock, if the system can
Allocate all the resource required by all the processes without entering into deadlock.
 Unsafe state: is a state that isn’t save, if the system can’t fulfill the request of all
Processes we called (unsafe state)

Pipe: is a circular buffer allowing two processes to communicate on the producer-consumer model.
Shared memory: is the fastest form of inter-process communication provided in UNIX, which is a
common block of virtual memory shared by multiple processes.
Semaphores: are ineger variables that are used to solve the critical section problem by using two
atomic operations wait and signal that are used for process synchronization.
Spinlock: is lock which causes a thread trying to acquire it to simply wait in a loop while repeatedly
checking if the lock is available.

Basic spinlocks: The basic spinlock comes in four flavors.


 Plain:
 IRQ: is a hardware signal sent to the processor that temporarily stops a running program
and allows a special program,
 BH: is generic operation system term refering to the deferred portion of interrupt processing.
 ReadeR–WRiteR spinlock: The reader–writer spinlock is a mechanism that allows a greater
degree of concurrency within the kernel than the basic spinlock.
 RCU (Read-copy-update) : mechanism is an advanced lightweight synchronization
mechanism which was integrated into the Linux kernel in 2002
Linux provides three types of semaphore facilities in the kernel
 Binary semaphores
 Counting semaphores
 Reader–writer semaphores

DeadLock Strategies
Swappable space: Prevention of deadlocks by requiring that all of the required resources that may be
used be allocated at one time,
Process resources: Avoidance will often be effective in this category, because it is reasonable to
expect processes to declare ahead of time the resources that they will require in this class.
Main memory: Prevention by preemption appears to be the most appropriate strategy for main
memory. When a process is preempted, it is simply swapped to secondary memory,
Internal resources: Prevention by means of resource ordering can be used.
Message: is a block of bytes with an accompanying type. UNIX provides msgsnd and msgrcv system
calls for processes to engage in message passing
Shared Memory: in UNIX shared memory is sharedby multiple processes. Processes read and write
shared memory using the same machine instructions they use to read and write other portions of their
virtual memory space.
Signals: the signsl operations increments the semaphore value by 1
Wait: the wait operations decrements the semaphore value by 1

UNIX Signals Value


SIGHUP, SIGINT, SIGEMT, SIGPIPE, SIGKILL and SIGBUS

Atomic Operations
Is a operation which a processor can simultaneously read a location and write it in the same bus
operation.
Integer operations: which operate on an integer variable.
Bitmap operations: which operate on one bit in a bitmap, atomic operations are the simplest of the
approaches to kernel synchroniza-tion.
SOLARIS THREAD SYNCHRONIZATION PRIMITIVES.
 Mutual exclusion (mutex) locks
 Semaphores.
 Multiple readers, single writer (readers/writer) locks
 Condition variables
Mutual exclusion: is used to ensure that only one thread at a time can access the resource pro-
tected by the mutex.
Multiple readers, single writer (readers/writer) locks: allows multiple threads to have
simultaneous read-only access to an object protected by the lock.
Kinds of Semaphores
 sema_p (): Decrements the semaphore, potentially blocking the thread
 sema_v (): Increments the semaphore, potentially unblocking a waiting thread.
 sema_tryp (): Decrements the semaphore if blocking is not required
 Again, the sema_tryp (): primitive permits busy waiting.

Condition variables: a condition variable is used to wait until a particular condition is true.
 cv_wait (): Blocks until the condition is signaled.
 cv_signal (): Wakes up one of the threads blocked in cv_wait ()
 cv_broadcast (): Wakes up all of the threads blocked in cv_wait ()
Wait Functions: allow a thread to block its own execution. The wait functions do not return until the
specified criteria have been met.
Dispatcher Objects
 Included timer objects
 Event objects
 Semaphore objects
 Mutex objects
 Thread objects
Windows Synchronization Objects Object
 Notification event
 Synchronization event
 Mutex: is used to enforce mutually exclusive access to a resource, allowing only one thread
object at a time to gain access.
 Semaphore: may be shared by threads in multiple processes
 Waitable timer: signals at a certain time and/or at regular intervals.

Binder: Binder provides a lightweight remote procedure call (RPC) capability that is efficient in
terms of both memory and processing requirements

You might also like