SlideShare une entreprise Scribd logo
1  sur  35
CRITICAL SECTION
PROBLEM
CS Problem
●   When one process is executing in its critical
    section, then no process is allowed to execute in its
    critical section, thus the execution of CS by the
    processes is mutually exclusive in time
CS Problem
do
{
entry section
     Critical Section
Exit section
     Remainder section
}while(1);
CS problem
●   A solution to CS problem must satisfy
    ●   Mutual exclusion: if process Pi is executing in its CS, then
        no other processes can be executing in their CS
    ●   Progress: if no process is executing in its CS and some
        processes want to enter thier CS, then only those processes
        that are not executing in their remainder section can
        participate in the decision on which will enter its CS next,
        and this selection cannot be postponed indefinitely
    ●   Bounded Waiting: There exists a bound on the number of
        times that other processes are allowed to enter their CS after
        a process has made a request to enter its CS and before that
        is granted
Two process solution for CS
●   Assume there are only two processes P0 and P1 at
    a time.
●   For convenience, when presenting Pi, we use Pj to
    denote the other process, that is j=1-i
Algorithm 1
Do{
  While (turn != i);
       Critical section
  Turn =j;
  Remainder section
  }while(1);
  if turn==i, then process Pi is allowed to execute CS
  ●  Mutual exclusion is satisfied, but the progress is not
     satisfied
  ●   If turn==0 and P1 is ready to enter CS, P1 cannot do,
      eventhough P0 may be in its remainder section
Algorithm 2
Do{
  flag[i] = true;
  while(flag[j])'
      Critical section
  flag[i]=false;
      Remainder section;
  }while(1);
Algorithm 2
●   Boolean flag[2];
●   If flag[i] is true, then P1 is allowed to enter its CS.
●   Mutual exclusion is satisfied and progress is not
    satisfied
●   P0 sets flag[0]=true;
●   P1 sets flag[1]=true;
●   Both P0 and P1 are looping forever in their
    respective while statements.
Algorithm 3
●   The processes share two variables
●   Boolean flag[2]
●   Int turn;
●   Initial values of flag[0] and flag[1] is false and turn
    value either 0 or 1 (immaterial)
●   All the three are satisfied
    ●   Progress
    ●   Mutual exclusion
    ●   Bounded waiting
Algorithm 3
Do{
  flag[i]=true;
  turn=j;
  while(flag[j] && turn ==j);
      Critical section
  flag[i]=false;
      Remainder section
}while(1);
Algorithm 3
●   Pi can enter its CS only when either flag[j]=false
    and turn=i
●   And if P0 and P1 change the flag[0] and flag[1]
    simultaneously to true and wanted to execute its
    CS, then turn =0 or 1 can happen only one at a
    time, so progress is satisfied.
Semaphores
●   Two atomic operations
●   P – wait – proberen (Dutch)
●   V – signal – verhogen
●   Pseudocode is
●   wait(S)
    While (S<=0)
    ;//no operation
    S--;
●   }
Semaphores
Signal (S)
  {
  S++;
  }
  ●   Modification to the integer value of the semaphore in
      the wait and singal operations.
  ●   That is when one process changes the semaphore value,
      no other process can simultaneously modify that same
      semaphore value.
Semaphore implementation
typedef struct {
Int value;
Struct process *L;
}semaphore;
each semaphore has an integer value and list of
  processes. When a process must wait on a
  semaphore, it is added to the list of processes.
●   A signal operation removes one process from the
    list of waiting processes and awakens that process
Semaphore implementation
Void wait(semaphore S){
    S.value--;
    if(S.value <0){
    Add this process to S.L;
    Block();
    }
}
Semaphore implementation
Void signal(Semaphore S){
    S.value++;
    if(S.value <=0){
    Remove a process P from S.L;
    wakeup(P);
    }
}
Deadlock Situations
• Mutual exclusion. At least one resource must be held in a
  non sharable mode; that is, only one process at a time can
  use the resource. If another process requests that
  resource, the requesting process must be delayed until the
  resource has been released.
• Hold and wait. A process must be holding at least one
  resource and waiting to acquire additional resources that
  are currently being held by other processes.
Deadlock
• No preemption. Resources cannot be preempted; that is,
  a resource can be released only voluntarily by the process
  holding it, after that process has completed its task.
• Circular wait. A set { P0 , Pl, ... , P11 } of waiting processes
  must exist such that Po is waiting for a resource held by
  P1, P1 is waiting for a resource held by P2, ... , Pn-1 is
  waiting for a resource held by P,v and P11 is waiting for a
  resource held by Po.
Resource Allocation Graph
• The sets P, K and E:
• P == {P1, P2, P3}
• R== {R1, R2, R3, ~}
• E == {Pl -> Rl P2-> R3, Rl->P2, R2->P2, R2-> Pl, R3-> P3}
• Resource instances:
• One instance of resource type R1
• Two instances of resource type R2
Resource Allocation Graph
Resource Allocation Graph
• One instance of resource type R3
• Three instances of Resource R4
• Process states:
  • Process P1 is holding an instance of resource type R2 and is
    waiting for an instance of resource type R1 .
  • Process P2 is holding an instance of R1 and an instance of R2 and
    is waiting for an instance of R3.
  • Process P3 is holding an instance of R3nces of resource type R4
Resource Allocation Graph
• One instance of resource type R3
• Three instances of Resource R4
• Process states:
  • Process P1 is holding an instance of resource type R2 and is
    waiting for an instance of resource type R1 .
  • Process P2 is holding an instance of R1 and an instance of R2 and
    is waiting for an instance of R3.
  • Process P3 is holding an instance of R3nces of resource type R4
Resource Allocation Graph
Resource Allocation Graph
• P1 ->R1-> P3-> R2-> P1 (P4 may release R2 so that the
 cycle breaks)
Handling Deadlocks
• We can use a protocol to prevent or avoid deadlocks,
  ensuring that the system will never enter a deadlocked
  state.
• We can allow the system to enter a deadlocked state,
  detect it, and recover.
• We can ignore the problem altogether and pretend that
  deadlocks never occur in the system. (used in windows
  and Unix OS)
Deadlock prevention
• Mutual Exclusion
  • Handles non-sharable resource
  • Read only files are the good examples, so any process can use
    that resource, since it is sharable
  • But printers are non sharable, they cannot be denied since printers
    are intrinsically non sharable
Deadlock prevention
• Hold and Wait
  • Whenever a process request any resource, it should not hold any
    other resource
  • Before a process begins its execution, all resource allocated to it.
  • But when the process needs any new resource during its
    execution, it should release the other resources.
  • Starvation is possible in this case, as some process will wait
    indefinitely to use a resource.
  • Also resource utilization is low, that is the resources are unused for
    a long period.
  • Example: if a process wanted to copy some files from a DVD to
    disk and then sort the files and printing it. A Process may request
    DVD and disk, once the copying is done, it may request the Printer
    rather than locking everything in the beginning.
Deadlock prevention
• No Preemption
  • If a process requests some resources, we first check whether they
    are available and we allocate them.
  • If they are not, we check whether they are allocated to some other
    process that is waiting for additional resources. If so, we preempt
    the desired resources from the waiting process and allocate them
    to the requesting process. If the resources are neither available nor
    held by a waiting process, the requesting process must wait. While
    it is waiting, some of its resources may be preempted, but only if
    another process requests them.
  • This protocol is often applied to resources whose state can be
    easily saved and restored later, such as CPU registers and memory
    space. It cannot generally be applied to such resources as printers
    and tape drives.
Deadlock prevention
• Circular Wait
  • To avoid deadlock with this, a number can be allotted to each
    resource
  • Any process can request the resource in terms of increasing order
  • For example F(tape)=1, F(disk)=5, F(printer) =12, a process which
    need tape and printer can request only tape first and then the
    printer. Till that time some other process can use the printer
  • While releasing the resource also, the processes will release in the
    descending order of Numbers.
Dining Philosophers Algorithm
Dining Philosophers Algorithm
Semaphore chopstick[5]={1};
Int I;
Room=4;
Void philosopher(int i)
{
While(TRUE){
Think();
Wait(room);
Wait(chopstick[i]);
Wait (chopstick[i+1]%5);
Eat();
signal(chopstick[i+1]%5);
signal(chopstick[i]);
Signal(room);
}
}
Deadlock Avoidance
• Requires knowledge of future process resource request
• Two approaches
   • do not start a process if its demands might lead to deadlock
   • Do not grant any incremental resource request to a process if this
     allocation might lead to deadlock
Deadlock Avoidance
Resource R = (R1,R2,……Rn)        Total amount of each resource in
                                 the system
Available V = (V1,V2,V3,…..Vn)   Total amount of each resource not
                                 allocated to any process
Claim C=                         Cij = requirement of process i for
c11 c12 ...... c1m               resource j
c21 c22 ...... c2m
....
Cn1 cn2........cnm
Allocation A =                   Aij = current allocation to process i of
a11 a12 ...... a1m               resource j
a21 a22 ...... a2m
....
an1 an2........anm
Banker’s algorithm
• Safe State
  • Is one in which there is at least one sequence of resource
    allocations to processes that does not result in deadlock (All
    process run to completion)
• Unsafe state
  • A state that is not safe
Banker’s algorithm

Contenu connexe

Tendances

Semaphores OS Basics
Semaphores OS BasicsSemaphores OS Basics
Semaphores OS BasicsShijin Raj P
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process SynchronizationSonali Chauhan
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphoresanandammca
 
Semaphores and Monitors
 Semaphores and Monitors Semaphores and Monitors
Semaphores and Monitorssathish sak
 
Process synchronization(deepa)
Process synchronization(deepa)Process synchronization(deepa)
Process synchronization(deepa)Nagarajan
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.MOHIT DADU
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksMukesh Chinta
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's typesNishant Joshi
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronizationvinay arora
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronizationAli Ahmad
 
Synchronization
SynchronizationSynchronization
SynchronizationMohd Arif
 

Tendances (20)

Semaphores OS Basics
Semaphores OS BasicsSemaphores OS Basics
Semaphores OS Basics
 
OS_Ch8
OS_Ch8OS_Ch8
OS_Ch8
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
Monitors
MonitorsMonitors
Monitors
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Deadlock
DeadlockDeadlock
Deadlock
 
Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphores
 
Semaphores and Monitors
 Semaphores and Monitors Semaphores and Monitors
Semaphores and Monitors
 
Process synchronization(deepa)
Process synchronization(deepa)Process synchronization(deepa)
Process synchronization(deepa)
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
OS_Ch7
OS_Ch7OS_Ch7
OS_Ch7
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Synchronization
SynchronizationSynchronization
Synchronization
 

En vedette

Lecture 1 introduction to operating systems
Lecture 1  introduction to operating systemsLecture 1  introduction to operating systems
Lecture 1 introduction to operating systemsPradeep Kumar TS
 
Lecture 3,4 operating systems
Lecture 3,4   operating systemsLecture 3,4   operating systems
Lecture 3,4 operating systemsPradeep Kumar TS
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationPradeep Kumar TS
 
Software Defined Networking - 1
Software Defined Networking - 1Software Defined Networking - 1
Software Defined Networking - 1Pradeep Kumar TS
 
Challenges in Embedded Computing
Challenges in Embedded ComputingChallenges in Embedded Computing
Challenges in Embedded ComputingPradeep Kumar TS
 
Virtual classrooms and labs using Big Blue Button
Virtual classrooms and labs using Big Blue ButtonVirtual classrooms and labs using Big Blue Button
Virtual classrooms and labs using Big Blue ButtonPradeep Kumar TS
 

En vedette (9)

Lecture 1 introduction to operating systems
Lecture 1  introduction to operating systemsLecture 1  introduction to operating systems
Lecture 1 introduction to operating systems
 
Lecture 7 cpu scheduling
Lecture 7   cpu schedulingLecture 7   cpu scheduling
Lecture 7 cpu scheduling
 
Lecture 3,4 operating systems
Lecture 3,4   operating systemsLecture 3,4   operating systems
Lecture 3,4 operating systems
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Software Defined Networking - 1
Software Defined Networking - 1Software Defined Networking - 1
Software Defined Networking - 1
 
Lecture 5 process concept
Lecture 5   process conceptLecture 5   process concept
Lecture 5 process concept
 
Challenges in Embedded Computing
Challenges in Embedded ComputingChallenges in Embedded Computing
Challenges in Embedded Computing
 
Virtual classrooms and labs using Big Blue Button
Virtual classrooms and labs using Big Blue ButtonVirtual classrooms and labs using Big Blue Button
Virtual classrooms and labs using Big Blue Button
 
Introduction to TCP
Introduction to TCPIntroduction to TCP
Introduction to TCP
 

Similaire à Cs problem [repaired]

OS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxOS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxGovindJha93
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptxKokilaK25
 
Deadlock Detection.pptx
Deadlock Detection.pptxDeadlock Detection.pptx
Deadlock Detection.pptxinfomerlin
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptxshreesha16
 
CPU SCHEDULING AND DEADLOCK
CPU SCHEDULING AND	DEADLOCKCPU SCHEDULING AND	DEADLOCK
CPU SCHEDULING AND DEADLOCKVicky Kumar
 
Chapter5_Deadlock.pptx
Chapter5_Deadlock.pptxChapter5_Deadlock.pptx
Chapter5_Deadlock.pptxDenisPriscus
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating SystemAUST
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptxshrijanasharma3
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptxsheraz7288
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.pptjayverma27
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdfKp Sharma
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptxJOHNZHOU52
 
programming .pptx
programming .pptxprogramming .pptx
programming .pptxSHUJEHASSAN
 

Similaire à Cs problem [repaired] (20)

OS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxOS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
Deadlock Detection.pptx
Deadlock Detection.pptxDeadlock Detection.pptx
Deadlock Detection.pptx
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
CPU SCHEDULING AND DEADLOCK
CPU SCHEDULING AND	DEADLOCKCPU SCHEDULING AND	DEADLOCK
CPU SCHEDULING AND DEADLOCK
 
Chapter5_Deadlock.pptx
Chapter5_Deadlock.pptxChapter5_Deadlock.pptx
Chapter5_Deadlock.pptx
 
Deadlock
DeadlockDeadlock
Deadlock
 
Dead lock
Dead lockDead lock
Dead lock
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 
Deadlocks Part- III.pdf
Deadlocks Part- III.pdfDeadlocks Part- III.pdf
Deadlocks Part- III.pdf
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 
Ipc feb4
Ipc feb4Ipc feb4
Ipc feb4
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
Ch7 deadlocks
Ch7   deadlocksCh7   deadlocks
Ch7 deadlocks
 
Os5
Os5Os5
Os5
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdf
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptx
 
programming .pptx
programming .pptxprogramming .pptx
programming .pptx
 

Plus de Pradeep Kumar TS

Digital Portfolio and Footprint
Digital Portfolio and FootprintDigital Portfolio and Footprint
Digital Portfolio and FootprintPradeep Kumar TS
 
Software Define Networking (SDN)
Software Define Networking (SDN)Software Define Networking (SDN)
Software Define Networking (SDN)Pradeep Kumar TS
 
What next - Career Enhancement of Graduates
What next - Career Enhancement of GraduatesWhat next - Career Enhancement of Graduates
What next - Career Enhancement of GraduatesPradeep Kumar TS
 
Higher Order Thinking - Question paper setting
Higher Order Thinking - Question paper settingHigher Order Thinking - Question paper setting
Higher Order Thinking - Question paper settingPradeep Kumar TS
 
IoT Communication Protocols
IoT Communication ProtocolsIoT Communication Protocols
IoT Communication ProtocolsPradeep Kumar TS
 
RPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy NetworksRPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy NetworksPradeep Kumar TS
 
Recompiling network simulator 2
Recompiling network simulator 2Recompiling network simulator 2
Recompiling network simulator 2Pradeep Kumar TS
 
OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2Pradeep Kumar TS
 
Wired and Wireless Examples in ns2
Wired and Wireless Examples in ns2Wired and Wireless Examples in ns2
Wired and Wireless Examples in ns2Pradeep Kumar TS
 
Software Defined Networking - 2
Software Defined Networking - 2Software Defined Networking - 2
Software Defined Networking - 2Pradeep Kumar TS
 
Software Defined Networking - 3
Software Defined Networking - 3Software Defined Networking - 3
Software Defined Networking - 3Pradeep Kumar TS
 

Plus de Pradeep Kumar TS (20)

Digital Portfolio and Footprint
Digital Portfolio and FootprintDigital Portfolio and Footprint
Digital Portfolio and Footprint
 
Open book Examination
Open book ExaminationOpen book Examination
Open book Examination
 
Software Define Networking (SDN)
Software Define Networking (SDN)Software Define Networking (SDN)
Software Define Networking (SDN)
 
What next - Career Enhancement of Graduates
What next - Career Enhancement of GraduatesWhat next - Career Enhancement of Graduates
What next - Career Enhancement of Graduates
 
Protothreads
ProtothreadsProtothreads
Protothreads
 
6LoWPAN
6LoWPAN 6LoWPAN
6LoWPAN
 
Software Defined Networks
Software Defined NetworksSoftware Defined Networks
Software Defined Networks
 
Higher Order Thinking - Question paper setting
Higher Order Thinking - Question paper settingHigher Order Thinking - Question paper setting
Higher Order Thinking - Question paper setting
 
IoT Communication Protocols
IoT Communication ProtocolsIoT Communication Protocols
IoT Communication Protocols
 
IoT Applications
IoT ApplicationsIoT Applications
IoT Applications
 
RPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy NetworksRPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy Networks
 
Mannasim for NS2
Mannasim for NS2Mannasim for NS2
Mannasim for NS2
 
Recompiling network simulator 2
Recompiling network simulator 2Recompiling network simulator 2
Recompiling network simulator 2
 
OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2
 
Wired and Wireless Examples in ns2
Wired and Wireless Examples in ns2Wired and Wireless Examples in ns2
Wired and Wireless Examples in ns2
 
Installation of ns2
Installation of ns2Installation of ns2
Installation of ns2
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Software Defined Networking - 2
Software Defined Networking - 2Software Defined Networking - 2
Software Defined Networking - 2
 
Software Defined Networking - 3
Software Defined Networking - 3Software Defined Networking - 3
Software Defined Networking - 3
 
Tracing and awk in ns2
Tracing and awk in ns2Tracing and awk in ns2
Tracing and awk in ns2
 

Dernier

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 

Dernier (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 

Cs problem [repaired]

  • 2. CS Problem ● When one process is executing in its critical section, then no process is allowed to execute in its critical section, thus the execution of CS by the processes is mutually exclusive in time
  • 3. CS Problem do { entry section Critical Section Exit section Remainder section }while(1);
  • 4. CS problem ● A solution to CS problem must satisfy ● Mutual exclusion: if process Pi is executing in its CS, then no other processes can be executing in their CS ● Progress: if no process is executing in its CS and some processes want to enter thier CS, then only those processes that are not executing in their remainder section can participate in the decision on which will enter its CS next, and this selection cannot be postponed indefinitely ● Bounded Waiting: There exists a bound on the number of times that other processes are allowed to enter their CS after a process has made a request to enter its CS and before that is granted
  • 5. Two process solution for CS ● Assume there are only two processes P0 and P1 at a time. ● For convenience, when presenting Pi, we use Pj to denote the other process, that is j=1-i
  • 6. Algorithm 1 Do{ While (turn != i); Critical section Turn =j; Remainder section }while(1); if turn==i, then process Pi is allowed to execute CS ● Mutual exclusion is satisfied, but the progress is not satisfied ● If turn==0 and P1 is ready to enter CS, P1 cannot do, eventhough P0 may be in its remainder section
  • 7. Algorithm 2 Do{ flag[i] = true; while(flag[j])' Critical section flag[i]=false; Remainder section; }while(1);
  • 8. Algorithm 2 ● Boolean flag[2]; ● If flag[i] is true, then P1 is allowed to enter its CS. ● Mutual exclusion is satisfied and progress is not satisfied ● P0 sets flag[0]=true; ● P1 sets flag[1]=true; ● Both P0 and P1 are looping forever in their respective while statements.
  • 9. Algorithm 3 ● The processes share two variables ● Boolean flag[2] ● Int turn; ● Initial values of flag[0] and flag[1] is false and turn value either 0 or 1 (immaterial) ● All the three are satisfied ● Progress ● Mutual exclusion ● Bounded waiting
  • 10. Algorithm 3 Do{ flag[i]=true; turn=j; while(flag[j] && turn ==j); Critical section flag[i]=false; Remainder section }while(1);
  • 11. Algorithm 3 ● Pi can enter its CS only when either flag[j]=false and turn=i ● And if P0 and P1 change the flag[0] and flag[1] simultaneously to true and wanted to execute its CS, then turn =0 or 1 can happen only one at a time, so progress is satisfied.
  • 12. Semaphores ● Two atomic operations ● P – wait – proberen (Dutch) ● V – signal – verhogen ● Pseudocode is ● wait(S) While (S<=0) ;//no operation S--; ● }
  • 13. Semaphores Signal (S) { S++; } ● Modification to the integer value of the semaphore in the wait and singal operations. ● That is when one process changes the semaphore value, no other process can simultaneously modify that same semaphore value.
  • 14. Semaphore implementation typedef struct { Int value; Struct process *L; }semaphore; each semaphore has an integer value and list of processes. When a process must wait on a semaphore, it is added to the list of processes. ● A signal operation removes one process from the list of waiting processes and awakens that process
  • 15. Semaphore implementation Void wait(semaphore S){ S.value--; if(S.value <0){ Add this process to S.L; Block(); } }
  • 16. Semaphore implementation Void signal(Semaphore S){ S.value++; if(S.value <=0){ Remove a process P from S.L; wakeup(P); } }
  • 17. Deadlock Situations • Mutual exclusion. At least one resource must be held in a non sharable mode; that is, only one process at a time can use the resource. If another process requests that resource, the requesting process must be delayed until the resource has been released. • Hold and wait. A process must be holding at least one resource and waiting to acquire additional resources that are currently being held by other processes.
  • 18. Deadlock • No preemption. Resources cannot be preempted; that is, a resource can be released only voluntarily by the process holding it, after that process has completed its task. • Circular wait. A set { P0 , Pl, ... , P11 } of waiting processes must exist such that Po is waiting for a resource held by P1, P1 is waiting for a resource held by P2, ... , Pn-1 is waiting for a resource held by P,v and P11 is waiting for a resource held by Po.
  • 19. Resource Allocation Graph • The sets P, K and E: • P == {P1, P2, P3} • R== {R1, R2, R3, ~} • E == {Pl -> Rl P2-> R3, Rl->P2, R2->P2, R2-> Pl, R3-> P3} • Resource instances: • One instance of resource type R1 • Two instances of resource type R2
  • 21. Resource Allocation Graph • One instance of resource type R3 • Three instances of Resource R4 • Process states: • Process P1 is holding an instance of resource type R2 and is waiting for an instance of resource type R1 . • Process P2 is holding an instance of R1 and an instance of R2 and is waiting for an instance of R3. • Process P3 is holding an instance of R3nces of resource type R4
  • 22. Resource Allocation Graph • One instance of resource type R3 • Three instances of Resource R4 • Process states: • Process P1 is holding an instance of resource type R2 and is waiting for an instance of resource type R1 . • Process P2 is holding an instance of R1 and an instance of R2 and is waiting for an instance of R3. • Process P3 is holding an instance of R3nces of resource type R4
  • 24. Resource Allocation Graph • P1 ->R1-> P3-> R2-> P1 (P4 may release R2 so that the cycle breaks)
  • 25. Handling Deadlocks • We can use a protocol to prevent or avoid deadlocks, ensuring that the system will never enter a deadlocked state. • We can allow the system to enter a deadlocked state, detect it, and recover. • We can ignore the problem altogether and pretend that deadlocks never occur in the system. (used in windows and Unix OS)
  • 26. Deadlock prevention • Mutual Exclusion • Handles non-sharable resource • Read only files are the good examples, so any process can use that resource, since it is sharable • But printers are non sharable, they cannot be denied since printers are intrinsically non sharable
  • 27. Deadlock prevention • Hold and Wait • Whenever a process request any resource, it should not hold any other resource • Before a process begins its execution, all resource allocated to it. • But when the process needs any new resource during its execution, it should release the other resources. • Starvation is possible in this case, as some process will wait indefinitely to use a resource. • Also resource utilization is low, that is the resources are unused for a long period. • Example: if a process wanted to copy some files from a DVD to disk and then sort the files and printing it. A Process may request DVD and disk, once the copying is done, it may request the Printer rather than locking everything in the beginning.
  • 28. Deadlock prevention • No Preemption • If a process requests some resources, we first check whether they are available and we allocate them. • If they are not, we check whether they are allocated to some other process that is waiting for additional resources. If so, we preempt the desired resources from the waiting process and allocate them to the requesting process. If the resources are neither available nor held by a waiting process, the requesting process must wait. While it is waiting, some of its resources may be preempted, but only if another process requests them. • This protocol is often applied to resources whose state can be easily saved and restored later, such as CPU registers and memory space. It cannot generally be applied to such resources as printers and tape drives.
  • 29. Deadlock prevention • Circular Wait • To avoid deadlock with this, a number can be allotted to each resource • Any process can request the resource in terms of increasing order • For example F(tape)=1, F(disk)=5, F(printer) =12, a process which need tape and printer can request only tape first and then the printer. Till that time some other process can use the printer • While releasing the resource also, the processes will release in the descending order of Numbers.
  • 31. Dining Philosophers Algorithm Semaphore chopstick[5]={1}; Int I; Room=4; Void philosopher(int i) { While(TRUE){ Think(); Wait(room); Wait(chopstick[i]); Wait (chopstick[i+1]%5); Eat(); signal(chopstick[i+1]%5); signal(chopstick[i]); Signal(room); } }
  • 32. Deadlock Avoidance • Requires knowledge of future process resource request • Two approaches • do not start a process if its demands might lead to deadlock • Do not grant any incremental resource request to a process if this allocation might lead to deadlock
  • 33. Deadlock Avoidance Resource R = (R1,R2,……Rn) Total amount of each resource in the system Available V = (V1,V2,V3,…..Vn) Total amount of each resource not allocated to any process Claim C= Cij = requirement of process i for c11 c12 ...... c1m resource j c21 c22 ...... c2m .... Cn1 cn2........cnm Allocation A = Aij = current allocation to process i of a11 a12 ...... a1m resource j a21 a22 ...... a2m .... an1 an2........anm
  • 34. Banker’s algorithm • Safe State • Is one in which there is at least one sequence of resource allocations to processes that does not result in deadlock (All process run to completion) • Unsafe state • A state that is not safe