SlideShare a Scribd company logo
Process Synchronization

   Organized By: V.A.




                          V.A.
                        CSED,TU
Disclaimer


  This is NOT A COPYRIGHT           MATERIAL

Content has been taken mainly from the following books:
   Operating Systems Concepts By Silberschatz & Galvin ,
          Operating systems By D M Dhamdhere,
          System Programming By John J Donovan
                         etc…




               VA.
               CSED,TU
Process & Synchronization

     Process – Program in Execution.

     Synchronization – Coordination.

     Independent process cannot affect or be affected by the execution of another
      process

     Cooperating process can affect or be affected by the execution of another
      process

     Advantages of process cooperation

          Information sharing
          Computation speed-up
          Modularity
          Convenience

                             VA.
                             CSED,TU
Buffer




         VA.
         CSED,TU
Bounded-Buffer – Shared-Memory Solution

     Shared Data
               #define BUFFER_SIZE 10
               typedef struct {
                  ...
               } item;

              item buffer [BUFFER_SIZE];
              int in = 0;
              int out = 0;

     Can only use BUFFER_SIZE-1 elements

                        VA.
                        CSED,TU
Producer – Consumer




              VA.
              CSED,TU
Bounded-Buffer – Producer


      while (true) {
          /* Produce an item */
           while (((in = (in + 1) % BUFFER SIZE count) == out)
            ; /* do nothing -- no free buffers */
           buffer[in] = item;
           in = (in + 1) % BUFFER SIZE;
        }




                      VA.
                      CSED,TU
Bounded Buffer – Consumer


         while (true) {
               while (in == out)
                    ; // do nothing -- nothing to consume

              // remove an item from the buffer
              item = buffer[out];
              out = (out + 1) % BUFFER SIZE;
           return item;
            }




                     VA.
                     CSED,TU
Setting Final value of Counter




                VA.
                CSED,TU
Buffer Types


     Paradigm for cooperating processes, producer process produces information that
      is consumed by a consumer process

          Unbounded-buffer places no practical limit on the size of the buffer

          Bounded-buffer assumes that there is a fixed buffer size




                              VA.
                              CSED,TU
RC & CS


    Race Condition – Where several processes access and manipulate the same data
     concurrently and the outcome of the execution depends on the particular order
     in which access takes place.



    Critical Section – Segment of code in which Process may be changing common
     variables, updating a table, writing a file and so on.




                           VA.
                           CSED,TU
Peterson’s Solution




              VA.
              CSED,TU
Peterson’s Solution
  Var       flag : array [0…1] of Boolean;
            Turn : 0..1;
  Begin
            Flag[0] = false;
            Flag[1] = false;
  Parbegin
      Repeat                                 Repeat
            Flag[0] = true                        Flag[1] = true
            Turn = 1                              Turn = 0
            While flag[1] && turn==1              While flag[0] && turn==0
              Do {nothing};                         Do {nothing};
            {Critical Section}                    {Critical Section}
            Flag[0] = false;                      Flag[1] = false;
            {Remainder}                           {Remainder}
      Forver;                                                 Forver;
  Parend
  end

                               VA.
                               CSED,TU
Peterson’s Solution




             VA.
             CSED,TU
Synchronization Hardware
    Many Systems provide hardware support for critical section code

    Uni-Processors – Could disable Interrupts

         Currently running code would execute without preemption
         Generally too inefficient on multiprocessor systems

    Modern machines provide special atomic hardware instructions
           Atomic :- Uninterruptible



         Either Test memory word and Set value
         Or Swap contents of two memory words


                            VA.
                            CSED,TU
TestAndSet Instruction

          Definition:

           boolean TestAndSet (boolean *target)
            {
              boolean rv = *target;
              *target = TRUE;
              return rv:
            }




                VA.
                CSED,TU
Solution using TestAndSet
    Shared Boolean variable Lock, Initialized to FALSE.

     Solution:
       do {
         while ( TestAndSet (&lock ))
                ; /* do nothing

            //   critical section

         lock = FALSE;

            //    remainder section

        } while ( TRUE);

                            VA.
                            CSED,TU
Swap Instruction

         Definition:

          void Swap (boolean *a, boolean *b)
           {
             boolean temp = *a;
             *a = *b;
             *b = temp:
           }




               VA.
               CSED,TU
Solution using Swap
    Shared Boolean variable lock initialized to FALSE, Each process has a
     local Boolean variable key.

     Solution:
       do {
           key = TRUE;
            while ( key == TRUE)
               Swap (&lock, &key );

               //   critical section

           lock = FALSE;

              //    remainder section

          } while ( TRUE);
                             VA.
                             CSED,TU
Semaphore
  Synchronization tool that does not require busy waiting
  Semaphore S – Integer Variable
  Two standard operations modify S: wait() and signal()
     Originally called P() and V()
  Less complicated


    Can only be accessed via two indivisible (atomic) operations
       wait (S) {
            while S <= 0
                 ; // no-op
              S--;
         }

         signal (S) {
            S++;
          }
                            VA.
                            CSED,TU
Semaphore as General Synchronization Tool

     Counting Semaphore – Integer value can range over an unrestricted domain

     Binary Semaphore – Integer value can range only between 0 and 1, Can be
      simpler to Implement

          Also known as Mutex locks

     Can implement a counting semaphore S as a binary semaphore

     Provides mutual exclusion
        Semaphore S; // initialized to 1
        wait (S);

              Critical Section
          signal (S);

                            VA.
                            CSED,TU
Semaphore Implementation
    Must guarantee that no two processes can execute wait () and signal ()
     on the same semaphore at the same time

    Thus, implementation becomes the critical section problem where the
     wait and signal code are placed in the critical section.

         Could now have busy waiting in critical section implementation
            But implementation code is short

            Little busy waiting if critical section rarely occupied



    Note that applications may spend lots of time in critical sections and
     therefore this is not a good solution.


                          VA.
                          CSED,TU
Semaphore Implementation with no Busy waiting

     With each Semaphore there is an associated waiting queue. Each entry in a
      waiting queue has two data items:

          Value (of type Integer)
          Pointer to next record in the list

     Two operations:

          Block – Place the Process invoking the operation on the appropriate waiting
           queue.
          Wakeup – Remove one of Processes in the waiting queue and place it in the
           ready queue.



                               VA.
                               CSED,TU
Semaphore Implementation with no Busy waiting
                                 (Cont.)
    Implementation of WAIT:

              wait (S){
                   value--;
                   if (value < 0) {
                            add this process to waiting queue
                             block(); }
              }

    Implementation of SIGNAL:

              Signal (S){
                     value++;
                      if (value <= 0) {
                               remove a process P from the waiting queue
                                wakeup(P); }
              }
                           VA.
                           CSED,TU
Deadlock and Starvation
    Deadlock – Two or more Processes are waiting Indefinitely for an event that can
     be caused by only one of the waiting processes

    Let S and Q be two Semaphores initialized to 1
                     P0                               P1
                 wait (S);                          wait (Q);
                 wait (Q);                          wait (S);
                     .                                  .
                     .                                  .
                     .                                  .
                signal (S);                          signal (Q);
                signal (Q);                          signal (S);

    Starvation – Indefinite Blocking. A process may never be removed from the
     semaphore queue in which it is suspended.


                            VA.
                            CSED,TU
Producer Consumer




           VA.
           CSED,TU
Solution to PC must satisfy 3 conditions




               VA.
               CSED,TU
Solution to PC with Busy Wait




              VA.
              CSED,TU
Solution to PC with Signaling




              VA.
              CSED,TU
Indivisible Operations for PC




              VA.
              CSED,TU
Readers & Writers in Banking System




             VA.
             CSED,TU
Correctness Condition for R-W Problem




               VA.
               CSED,TU
Solution outline for R-W without Writer priority




                   VA.
                   CSED,TU
Dining Philosophers




             VA.
             CSED,TU
Outline of a Philosopher Process Pi




              VA.
              CSED,TU
An Improved Outline of a Philosopher
             Process




            VA.
            CSED,TU
Reference List


Operating Systems Concepts By Silberschatz & Galvin,
       Operating systems By D M Dhamdhere,
      System Programming By John J Donovan,

                    www.os-book.com
    www.cs.jhu.edu/~yairamir/cs418/os2/sld001.htm
http://gaia.ecs.csus.edu/~zhangd/oscal/pscheduling.html
  http://www.edugrid.ac.in/iiitmk/os/os_module03.htm
     http://williamstallings.com/OS/Animations.html
                        etc…


             VA.
             CSED,TU
Thnx…



VA.
CSED,TU

More Related Content

What's hot

OSCh7
OSCh7OSCh7
Synchronization
SynchronizationSynchronization
Synchronization
Mohd Arif
 
SYNCHRONIZATION
SYNCHRONIZATIONSYNCHRONIZATION
SYNCHRONIZATION
atanuanwesha
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
Ra'Fat Al-Msie'deen
 
Operating System-Ch6 process synchronization
Operating System-Ch6 process synchronizationOperating System-Ch6 process synchronization
Operating System-Ch6 process synchronization
Syaiful Ahdan
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
Harshana Madusanka Jayamaha
 
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
 
ITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded bufferITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded buffer
Sneh Prabha
 
Os module 2 c
Os module 2 cOs module 2 c
Os module 2 c
Gichelle Amon
 
Semaphores OS Basics
Semaphores OS BasicsSemaphores OS Basics
Semaphores OS Basics
Shijin Raj P
 
Os3
Os3Os3
Ch7 Process Synchronization galvin
Ch7 Process Synchronization galvinCh7 Process Synchronization galvin
Ch7 Process Synchronization galvin
Shubham Singh
 
Monitors
MonitorsMonitors
Monitors
Mohd Arif
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
Mukesh Chinta
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
Anas Ebrahim
 
Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphores
anandammca
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
Ali Ahmad
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
Bipul Chandra Kar
 
Behavioral modeling
Behavioral modelingBehavioral modeling
Behavioral modeling
dennis gookyi
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
Syed Hassan Ali
 

What's hot (20)

OSCh7
OSCh7OSCh7
OSCh7
 
Synchronization
SynchronizationSynchronization
Synchronization
 
SYNCHRONIZATION
SYNCHRONIZATIONSYNCHRONIZATION
SYNCHRONIZATION
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
Operating System-Ch6 process synchronization
Operating System-Ch6 process synchronizationOperating System-Ch6 process synchronization
Operating System-Ch6 process synchronization
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
ITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded bufferITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded buffer
 
Os module 2 c
Os module 2 cOs module 2 c
Os module 2 c
 
Semaphores OS Basics
Semaphores OS BasicsSemaphores OS Basics
Semaphores OS Basics
 
Os3
Os3Os3
Os3
 
Ch7 Process Synchronization galvin
Ch7 Process Synchronization galvinCh7 Process Synchronization galvin
Ch7 Process Synchronization galvin
 
Monitors
MonitorsMonitors
Monitors
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
 
Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphores
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
 
Behavioral modeling
Behavioral modelingBehavioral modeling
Behavioral modeling
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 

Viewers also liked

Security & Protection
Security & ProtectionSecurity & Protection
Security & Protection
vinay arora
 
Uta005 lecture1
Uta005 lecture1Uta005 lecture1
Uta005 lecture1
vinay arora
 
4 java - decision
4  java - decision4  java - decision
4 java - decision
vinay arora
 
2 java - operators
2  java - operators2  java - operators
2 java - operators
vinay arora
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
vinay arora
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
vinay arora
 
Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawler
vinay arora
 
3 java - variable type
3  java - variable type3  java - variable type
3 java - variable type
vinay arora
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
vinay arora
 
Uta005 lecture2
Uta005 lecture2Uta005 lecture2
Uta005 lecture2
vinay arora
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphics
vinay arora
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devices
vinay arora
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
vinay arora
 

Viewers also liked (13)

Security & Protection
Security & ProtectionSecurity & Protection
Security & Protection
 
Uta005 lecture1
Uta005 lecture1Uta005 lecture1
Uta005 lecture1
 
4 java - decision
4  java - decision4  java - decision
4 java - decision
 
2 java - operators
2  java - operators2  java - operators
2 java - operators
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
 
Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawler
 
3 java - variable type
3  java - variable type3  java - variable type
3 java - variable type
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
 
Uta005 lecture2
Uta005 lecture2Uta005 lecture2
Uta005 lecture2
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphics
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devices
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
 

Similar to Process Synchronization

Lecture18-19 (1).ppt
Lecture18-19 (1).pptLecture18-19 (1).ppt
Lecture18-19 (1).ppt
ssuserf67e3a
 
CH05.pdf
CH05.pdfCH05.pdf
CH05.pdf
ImranKhan880955
 
Writing more complex models
Writing more complex modelsWriting more complex models
Writing more complex models
Mohamed Samy
 
Operating System
Operating SystemOperating System
Operating System
Subhasis Dash
 
OS Process synchronization Unit3 synchronization
OS Process synchronization Unit3  synchronizationOS Process synchronization Unit3  synchronization
OS Process synchronization Unit3 synchronization
subhamchy2005
 
Clockless design language - ilia greenblat
Clockless design language - ilia greenblatClockless design language - ilia greenblat
Clockless design language - ilia greenblat
chiportal
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
Guy Korland
 
Lecture_6_Process.ppt
Lecture_6_Process.pptLecture_6_Process.ppt
Lecture_6_Process.ppt
wafawafa52
 
Synchronization in os.pptx
Synchronization in os.pptxSynchronization in os.pptx
Synchronization in os.pptx
AbdullahBhatti53
 
Arduino - Module 1.pdf
Arduino - Module 1.pdfArduino - Module 1.pdf
Arduino - Module 1.pdf
razonclarence4
 
Os2
Os2Os2
Os2
issbp
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
Dhaval Shukla
 
VHDL Subprograms and Packages
VHDL Subprograms and PackagesVHDL Subprograms and Packages
VHDL Subprograms and Packages
Ramasubbu .P
 
Ch7
Ch7Ch7
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special Cases
Ciklum Ukraine
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
Intelligo Technologies
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
Intelligo Technologies
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
Sri Prasanna
 
Mca ii os u-2 process management & communication
Mca  ii  os u-2 process management & communicationMca  ii  os u-2 process management & communication
Mca ii os u-2 process management & communication
Rai University
 
Os4
Os4Os4
Os4
issbp
 

Similar to Process Synchronization (20)

Lecture18-19 (1).ppt
Lecture18-19 (1).pptLecture18-19 (1).ppt
Lecture18-19 (1).ppt
 
CH05.pdf
CH05.pdfCH05.pdf
CH05.pdf
 
Writing more complex models
Writing more complex modelsWriting more complex models
Writing more complex models
 
Operating System
Operating SystemOperating System
Operating System
 
OS Process synchronization Unit3 synchronization
OS Process synchronization Unit3  synchronizationOS Process synchronization Unit3  synchronization
OS Process synchronization Unit3 synchronization
 
Clockless design language - ilia greenblat
Clockless design language - ilia greenblatClockless design language - ilia greenblat
Clockless design language - ilia greenblat
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
 
Lecture_6_Process.ppt
Lecture_6_Process.pptLecture_6_Process.ppt
Lecture_6_Process.ppt
 
Synchronization in os.pptx
Synchronization in os.pptxSynchronization in os.pptx
Synchronization in os.pptx
 
Arduino - Module 1.pdf
Arduino - Module 1.pdfArduino - Module 1.pdf
Arduino - Module 1.pdf
 
Os2
Os2Os2
Os2
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
 
VHDL Subprograms and Packages
VHDL Subprograms and PackagesVHDL Subprograms and Packages
VHDL Subprograms and Packages
 
Ch7
Ch7Ch7
Ch7
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special Cases
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
Mca ii os u-2 process management & communication
Mca  ii  os u-2 process management & communicationMca  ii  os u-2 process management & communication
Mca ii os u-2 process management & communication
 
Os4
Os4Os4
Os4
 

More from vinay arora

Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)
vinay arora
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
vinay arora
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)
vinay arora
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)
vinay arora
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devices
vinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
vinay arora
 
A&D - UML
A&D - UMLA&D - UML
A&D - UML
vinay arora
 
A&D - Object Oriented Design using UML
A&D - Object Oriented Design using UMLA&D - Object Oriented Design using UML
A&D - Object Oriented Design using UML
vinay arora
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
vinay arora
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
vinay arora
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
vinay arora
 
A&D - Input Design
A&D - Input DesignA&D - Input Design
A&D - Input Design
vinay arora
 
A&D - Object Oriented Analysis using UML
A&D - Object Oriented Analysis using UMLA&D - Object Oriented Analysis using UML
A&D - Object Oriented Analysis using UML
vinay arora
 
A&D - Use Case Diagram
A&D - Use Case DiagramA&D - Use Case Diagram
A&D - Use Case Diagram
vinay arora
 
A&D - Output
A&D - OutputA&D - Output
A&D - Output
vinay arora
 

More from vinay arora (17)

Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devices
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
 
A&D - UML
A&D - UMLA&D - UML
A&D - UML
 
A&D - Object Oriented Design using UML
A&D - Object Oriented Design using UMLA&D - Object Oriented Design using UML
A&D - Object Oriented Design using UML
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
A&D - Input Design
A&D - Input DesignA&D - Input Design
A&D - Input Design
 
A&D - Object Oriented Analysis using UML
A&D - Object Oriented Analysis using UMLA&D - Object Oriented Analysis using UML
A&D - Object Oriented Analysis using UML
 
A&D - Use Case Diagram
A&D - Use Case DiagramA&D - Use Case Diagram
A&D - Use Case Diagram
 
A&D - Output
A&D - OutputA&D - Output
A&D - Output
 

Recently uploaded

How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 

Process Synchronization

  • 1. Process Synchronization Organized By: V.A. V.A. CSED,TU
  • 2. Disclaimer This is NOT A COPYRIGHT MATERIAL Content has been taken mainly from the following books: Operating Systems Concepts By Silberschatz & Galvin , Operating systems By D M Dhamdhere, System Programming By John J Donovan etc… VA. CSED,TU
  • 3. Process & Synchronization  Process – Program in Execution.  Synchronization – Coordination.  Independent process cannot affect or be affected by the execution of another process  Cooperating process can affect or be affected by the execution of another process  Advantages of process cooperation  Information sharing  Computation speed-up  Modularity  Convenience VA. CSED,TU
  • 4. Buffer VA. CSED,TU
  • 5. Bounded-Buffer – Shared-Memory Solution  Shared Data #define BUFFER_SIZE 10 typedef struct { ... } item; item buffer [BUFFER_SIZE]; int in = 0; int out = 0;  Can only use BUFFER_SIZE-1 elements VA. CSED,TU
  • 6. Producer – Consumer VA. CSED,TU
  • 7. Bounded-Buffer – Producer while (true) { /* Produce an item */ while (((in = (in + 1) % BUFFER SIZE count) == out) ; /* do nothing -- no free buffers */ buffer[in] = item; in = (in + 1) % BUFFER SIZE; } VA. CSED,TU
  • 8. Bounded Buffer – Consumer while (true) { while (in == out) ; // do nothing -- nothing to consume // remove an item from the buffer item = buffer[out]; out = (out + 1) % BUFFER SIZE; return item; } VA. CSED,TU
  • 9. Setting Final value of Counter VA. CSED,TU
  • 10. Buffer Types  Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process  Unbounded-buffer places no practical limit on the size of the buffer  Bounded-buffer assumes that there is a fixed buffer size VA. CSED,TU
  • 11. RC & CS  Race Condition – Where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which access takes place.  Critical Section – Segment of code in which Process may be changing common variables, updating a table, writing a file and so on. VA. CSED,TU
  • 12. Peterson’s Solution VA. CSED,TU
  • 13. Peterson’s Solution Var flag : array [0…1] of Boolean; Turn : 0..1; Begin Flag[0] = false; Flag[1] = false; Parbegin Repeat Repeat Flag[0] = true Flag[1] = true Turn = 1 Turn = 0 While flag[1] && turn==1 While flag[0] && turn==0 Do {nothing}; Do {nothing}; {Critical Section} {Critical Section} Flag[0] = false; Flag[1] = false; {Remainder} {Remainder} Forver; Forver; Parend end VA. CSED,TU
  • 14. Peterson’s Solution VA. CSED,TU
  • 15. Synchronization Hardware  Many Systems provide hardware support for critical section code  Uni-Processors – Could disable Interrupts  Currently running code would execute without preemption  Generally too inefficient on multiprocessor systems  Modern machines provide special atomic hardware instructions  Atomic :- Uninterruptible  Either Test memory word and Set value  Or Swap contents of two memory words VA. CSED,TU
  • 16. TestAndSet Instruction Definition: boolean TestAndSet (boolean *target) { boolean rv = *target; *target = TRUE; return rv: } VA. CSED,TU
  • 17. Solution using TestAndSet  Shared Boolean variable Lock, Initialized to FALSE. Solution: do { while ( TestAndSet (&lock )) ; /* do nothing // critical section lock = FALSE; // remainder section } while ( TRUE); VA. CSED,TU
  • 18. Swap Instruction Definition: void Swap (boolean *a, boolean *b) { boolean temp = *a; *a = *b; *b = temp: } VA. CSED,TU
  • 19. Solution using Swap  Shared Boolean variable lock initialized to FALSE, Each process has a local Boolean variable key. Solution: do { key = TRUE; while ( key == TRUE) Swap (&lock, &key ); // critical section lock = FALSE; // remainder section } while ( TRUE); VA. CSED,TU
  • 20. Semaphore  Synchronization tool that does not require busy waiting  Semaphore S – Integer Variable  Two standard operations modify S: wait() and signal()  Originally called P() and V()  Less complicated  Can only be accessed via two indivisible (atomic) operations  wait (S) { while S <= 0 ; // no-op S--; }  signal (S) { S++; } VA. CSED,TU
  • 21. Semaphore as General Synchronization Tool  Counting Semaphore – Integer value can range over an unrestricted domain  Binary Semaphore – Integer value can range only between 0 and 1, Can be simpler to Implement  Also known as Mutex locks  Can implement a counting semaphore S as a binary semaphore  Provides mutual exclusion  Semaphore S; // initialized to 1  wait (S); Critical Section signal (S); VA. CSED,TU
  • 22. Semaphore Implementation  Must guarantee that no two processes can execute wait () and signal () on the same semaphore at the same time  Thus, implementation becomes the critical section problem where the wait and signal code are placed in the critical section.  Could now have busy waiting in critical section implementation  But implementation code is short  Little busy waiting if critical section rarely occupied  Note that applications may spend lots of time in critical sections and therefore this is not a good solution. VA. CSED,TU
  • 23. Semaphore Implementation with no Busy waiting  With each Semaphore there is an associated waiting queue. Each entry in a waiting queue has two data items:  Value (of type Integer)  Pointer to next record in the list  Two operations:  Block – Place the Process invoking the operation on the appropriate waiting queue.  Wakeup – Remove one of Processes in the waiting queue and place it in the ready queue. VA. CSED,TU
  • 24. Semaphore Implementation with no Busy waiting (Cont.)  Implementation of WAIT: wait (S){ value--; if (value < 0) { add this process to waiting queue block(); } }  Implementation of SIGNAL: Signal (S){ value++; if (value <= 0) { remove a process P from the waiting queue wakeup(P); } } VA. CSED,TU
  • 25. Deadlock and Starvation  Deadlock – Two or more Processes are waiting Indefinitely for an event that can be caused by only one of the waiting processes  Let S and Q be two Semaphores initialized to 1 P0 P1 wait (S); wait (Q); wait (Q); wait (S); . . . . . . signal (S); signal (Q); signal (Q); signal (S);  Starvation – Indefinite Blocking. A process may never be removed from the semaphore queue in which it is suspended. VA. CSED,TU
  • 26. Producer Consumer VA. CSED,TU
  • 27. Solution to PC must satisfy 3 conditions VA. CSED,TU
  • 28. Solution to PC with Busy Wait VA. CSED,TU
  • 29. Solution to PC with Signaling VA. CSED,TU
  • 30. Indivisible Operations for PC VA. CSED,TU
  • 31. Readers & Writers in Banking System VA. CSED,TU
  • 32. Correctness Condition for R-W Problem VA. CSED,TU
  • 33. Solution outline for R-W without Writer priority VA. CSED,TU
  • 34. Dining Philosophers VA. CSED,TU
  • 35. Outline of a Philosopher Process Pi VA. CSED,TU
  • 36. An Improved Outline of a Philosopher Process VA. CSED,TU
  • 37. Reference List Operating Systems Concepts By Silberschatz & Galvin, Operating systems By D M Dhamdhere, System Programming By John J Donovan, www.os-book.com www.cs.jhu.edu/~yairamir/cs418/os2/sld001.htm http://gaia.ecs.csus.edu/~zhangd/oscal/pscheduling.html http://www.edugrid.ac.in/iiitmk/os/os_module03.htm http://williamstallings.com/OS/Animations.html etc… VA. CSED,TU