Hardware Support for Mutual Exclusion

download Hardware Support for Mutual Exclusion

of 15

Transcript of Hardware Support for Mutual Exclusion

  • 7/31/2019 Hardware Support for Mutual Exclusion

    1/15

    Hardware supports for mutual

    Exclusion

    Lince Sebastian

    S4Mca

    Roll: 26

  • 7/31/2019 Hardware Support for Mutual Exclusion

    2/15

  • 7/31/2019 Hardware Support for Mutual Exclusion

    3/15

    Pessimistic approaches

    Optimistic approaches

  • 7/31/2019 Hardware Support for Mutual Exclusion

    4/15

    Pessimistic approaches

    It tends to assume worst possible case and to

    defend against it by rather austere measures

    that often end up limiting concurrency

  • 7/31/2019 Hardware Support for Mutual Exclusion

    5/15

    Pessimistic Solution

    Block everything that could possibly interfere,

    so their should nothing to interfere..

    Update the global variable

    Unblock

  • 7/31/2019 Hardware Support for Mutual Exclusion

    6/15

    Optimistic approaches

    Optimistic approaches are based on

    assumption that no or few conflicts are likely

    to experienced by any particular user of

    shared recourse

  • 7/31/2019 Hardware Support for Mutual Exclusion

    7/15

    Optimistic Solution

    Read the value of the global variable andprepare the tentative local update based onthat value the global variable remains

    accessible to others users Compare the current value of global variable

    to the value used to prepare the tentativeupdate. If value of global variable isunchanged, the tentative local update toglobal variable , discard the tentative update..

  • 7/31/2019 Hardware Support for Mutual Exclusion

    8/15

    Disable/ enable interrupt (P)

    The basic idea is quite simple ..it follows the

    principle that shared resources must be

    exclusively obtained by the process wishing to

    enter its critical section subsequently released

    for the use of others

  • 7/31/2019 Hardware Support for Mutual Exclusion

    9/15

    while (true) {

    /* disable interrupts */

    /* critical section *//* enable interrupts */

    /* remainder */

    }

  • 7/31/2019 Hardware Support for Mutual Exclusion

    10/15

    Test and set instruction(P)

    In this assigning the global variable to FREE

    (0)when the guarded shared resource is

    available

    Check the status of global variable.

    If s=0, then resource is available

    If s=1, denotes busy state.

    Initially s will be 0

  • 7/31/2019 Hardware Support for Mutual Exclusion

    11/15

    The function of the test and set instruction may be presented as the

    following function:

    boolean testset (int i){

    if (i == 0)

    {

    i = 1;return true;

    }

    else

    {

    return false;

    }

    }

  • 7/31/2019 Hardware Support for Mutual Exclusion

    12/15

    Compare and swap instruction(o)

    Updating the global variable in the presence

    of concurrent activity and without any support

    from OS or the interrupt mechanism.

    Here copying the value of global variable to

    local space and using the value to calculate

    the tentative update.

  • 7/31/2019 Hardware Support for Mutual Exclusion

    13/15

    The value of global variable is not disturbed by

    any other process during the calculation of the

    update, the tentative update is applied to the

    global variable and thus made it permanent.

    Independent from interrupt mechanism .

    Can used in multiprocessor environment.

    Running process is always capable of making

    progress towards its completion.

  • 7/31/2019 Hardware Support for Mutual Exclusion

    14/15

  • 7/31/2019 Hardware Support for Mutual Exclusion

    15/15

    No Claps please

    Thank you