ch6a

download ch6a

of 41

Transcript of ch6a

  • 7/24/2019 ch6a

    1/41

    Silberschatz, Galvin and Gagne 2007Operating System Concepts with Java 7thEdition, Nov 15, 2006

    Chapter 6 (a): Synchronization

  • 7/24/2019 ch6a

    2/41

    6.2 Silberschatz, Galvin and Gagne 2007Operating System Concepts with Java 7thEdition, Nov 15, 2006

    Module 6: Process Synchronization

    Background Producer/Consumer Again Race Conditions Scheduler Assumptions The Critical-Section Problem

    Critical Section Goals Deriving a Solution Petersons Algorithm Baker! Algorithm "ard#are Support

  • 7/24/2019 ch6a

    3/41

    6.3 Silberschatz, Galvin and Gagne 2007Operating System Concepts with Java 7thEdition, Nov 15, 2006

    Background

    Concurrent access to shared data ma! result in data

    inconsistenc! $aintaining data consistenc! re%uires mechanisms to

    ensure the orderl! e&ecution o' cooperatingprocesses

    Suppose that #e #anted to provide a solution to theconsumer-producer problem that 'ills all the bu''ers( "ave an integer countthat tracks the number o' 'ull

    bu''ers( )nitiall!* count is set to +( Producer increments count a'ter producing a bu''er Consumer decrements a'ter consuming a bu''er

  • 7/24/2019 ch6a

    4/41

    6.4 Silberschatz, Galvin and Gagne 2007Operating System Concepts with Java 7thEdition, Nov 15, 2006

    Producer-Consumer

    Producer

    #hile ,true .

    / produce an item and /

    / put in ne&tProduced /

    #hile ,count 00 B1223R4S)53

    6 // do nothing b/c 'ull

    bu''er 7in8 0 ne&tProduced6

    in 0 ,in 9 : ; B1223R4S)536

    count996

  • 7/24/2019 ch6a

    5/41

    6.5 Silberschatz, Galvin and Gagne 2007Operating System Concepts with Java 7thEdition, Nov 15, 2006

    Race Condition

    count99could be implemented as

    register: 0 count register: 0 register: 9 : count 0 register:

    count--could be implemented as

    register= 0 count register= 0 register= - : count 0 register=

    Consider this e&ecution interleaving #ith >count 0 ?@ initiall!

    S+ producer e&ecute register: 0 count .register: 0 ?