ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > zstu-(2021-2022)-1 > homework noticement >
homework 6 Patience Fero Version 0
👤 Author: by feropatienceoutlookcom 2021-12-01 03:11:46
PATIENCE FERO 2019529628044

 

Solution is a classical software based solution to the critical section problem.

In  solution, we have two shared variables:

  • boolean flag[i] :Initialized to FALSE, initially no one is interested in entering the critical section

  • int turn : The process whose turn is to enter the critical section.


do { 

      flag[i] = TRUE

     turn = j;

     while(flag[j]  && turn == j)

           critical section

       flag[i ] = FALSE;

           reminder section

  }    while (TRUE)

Solution preserves all three conditions :

  • Mutual Exclusion is assured as only one process can access the critical section at any time.

  • Progress is also assured, as a process outside the critical section does not block other processes from entering the critical section.

  • Bounded Waiting is preserved as every process gets a fair chance.


Disadvantages of Solution

  • It involves Busy waiting

  • It is limited to 2 processes.


TestAndSet
TestAndSet is a hardware solution to the synchronization problem. In TestAndSet, we have a shared lock variable which can take either of the two values, 0 or 1.

0 Unlock

1 Lock

Before entering into the critical section, a process inquires about the lock. If it is locked, it keeps on waiting till it becomes free and if it is not locked, it takes the lock and executes the critical section.

In TestAndSet, Mutual exclusion and progress are preserved but bounded waiting cannot be preserved.

 

Please login to reply. Login

Reversion History

Loading...
No reversions found.