+ All Categories
Home > Documents > Synchronisation Hardware

Synchronisation Hardware

Date post: 06-Jul-2018
Category:
Upload: tarun
View: 230 times
Download: 0 times
Share this document with a friend

of 17

Transcript
  • 8/17/2019 Synchronisation Hardware

    1/17

    SYNCHRONISATION

    HARDWARETARUN KUMAR [email protected]

  • 8/17/2019 Synchronisation Hardware

    2/17

  • 8/17/2019 Synchronisation Hardware

    3/17

    CS Problem DynamicsWhen a process executes code that manipulates shareddata (or resource), we say that the process is in it’s CriticalSection (for that shared data).The execution of critical sections must be mutuallyexclusive: at any time, only one process is allowed toexecute in its critical section (even with multiple processors).So each process must first request permission to enter itscritical section.

  • 8/17/2019 Synchronisation Hardware

    4/17

    CS Problem Dynamics (cont..)

    The section of code implementing this request is called theEntry Section (ES).

    The critical section (CS) might be followed by a Leave/ExitSection (LS).

    The remaining code is the Remainder Section (RS).

    The critical section problem is to design a protocol that theprocesses can use so that their action will not depend onthe order in which their execution is interleaved (possibly on

    many processors).

  • 8/17/2019 Synchronisation Hardware

    5/17

    General structure of

    process P i (other is P j )do {critical section

    remainder section} while (TRUE);

    Processes may share some common variables to synchronize

    their actions.

    entry section

    leave section

  • 8/17/2019 Synchronisation Hardware

    6/17

    Solution to CS Problem

    There are 3 requirements that must stand for a correctsolution:

    1. Mutual Exclusion

    2. Progress

    3. Bounded WaitingWe can check on all three requirements in each proposedsolution, even though the non-existence of each one ofthem is enough for an incorrect solution.

  • 8/17/2019 Synchronisation Hardware

    7/17

    Mutual Exclusion

    If process P i is executing in its critical section, then no otherprocesses can be executing in their critical sections.

    Implications:

    Critical sections better be focused and short.

    Better not get into an infinite loop in there.If a process somehow halts/waits in its critical section, itmust not interfere with other processes.

  • 8/17/2019 Synchronisation Hardware

    8/17

    Progress

    If no process is executing in its critical section andthere exist some processes that wish to enter theircritical section, then the selection of the process thatwill enter the critical section next cannot be postponedindefinitely:

    • If only one process wants to enter, it should beable to.

    • If two or more want to enter, one of them shouldsucceed.

  • 8/17/2019 Synchronisation Hardware

    9/17

    Bounded Waiting

    A bound must exist on the number of times that otherprocesses are allowed to enter their critical sectionsafter a process has made a request to enter its criticalsection and before that request is granted.

    • Assume that each process executes at a nonzero speed.

    • No assumption concerning relative speed of then processes.

  • 8/17/2019 Synchronisation Hardware

    10/17

    Types of solutions to CS Problem

    Software solutions –• algorithms who’s correctness does not rely on any other

    assumptions.Hardware solutions –• rely on some special machine instructions.

    Operating System solutions –• provide some functions and data structures to the

    programmer through system/library calls.Programming Language solutions –

    • Linguistic constructs provided as part of a language.

  • 8/17/2019 Synchronisation Hardware

    11/17

    Synchronization Hardware

    Many systems provide hardware support for criticalsection codeUniprocessors – could disable interrupts

    Currently running code would execute withoutpreemptionGenerally too inefficient on multiprocessorsystems

    • Operating systems using this not broadlyscalable

  • 8/17/2019 Synchronisation Hardware

    12/17

    Synchronization Hardware (c

    Modern machines provide special atomic hardwareinstructions

    • Atomic = non-interruptibleEither test memory word and set value

    Or swap contents of two memory words

  • 8/17/2019 Synchronisation Hardware

    13/17

  • 8/17/2019 Synchronisation Hardware

    14/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);

  • 8/17/2019 Synchronisation Hardware

    15/17

  • 8/17/2019 Synchronisation Hardware

    16/17

    Solution using Swap()Shared Boolean variable lock initialized to FALSE ; Eachprocess has a local Boolean variable keySolution:

    do {key = TRUE;while ( key == TRUE)

    Swap (&lock, &key );// critical section

    lock = FALSE;// remainder section

    } while (TRUE);

  • 8/17/2019 Synchronisation Hardware

    17/17

    Bounded-waiting Mutual

    Exclusion with TestandSet()do {waiting[i] = TRUE;key = TRUE;

    while (waiting[i] && key)key = TestAndSet(&lock);

    waiting[i] = FALSE;// critical section

    j = (i + 1) % n;

    while ((j != i) && !waiti j = (j + 1) % n;

    if (j == i)

    lock = FALSE;else

    waiting[j] = FALSE;// remainder section

    } while (TRUE);


Recommended