algorithm - Bound wait to solve race condition -
i trying give race condition example , write algorithm impose synchronization , write algorithm implement bounded wait solution?! tried case of when 2 admins , b in school receive 2 students register them if hit save in same time 2 students have same id
then used semaphore solve following :-
start initialization { wait(semaphore); submitting order generate id; \\ critical section signal(semaphore); }while (true);
i did not know correct , satisfy bound wait?!!!
bounded waiting defined :-
there exists bound, or limit, on number of times other processes allowed enter critical sections after process has made request enter critical section , before request granted.
returning problem, it example of bounded waiting,but between 2 processes. doesn't make realise several of processes contending execution of critical-section. better example bounded waiting.would :-
when n
admins a[1],a[2],..,a[n] in school receive students register them, if hit save in same time students have same id. so, @ time single admin allowed execute critical section code(i.e., register student).
then, returning solution using semaphores, following :-
the n processes share semaphore,mutex
, initialised 1. each process a[i] organised :-
do{ wait(mutex); // critical section signal(mutex); // remainder section } while(true);
this 1 of way, but, unfortunately, doesn't give idea bounded waiting. here, can introduce additional constraint satisfaction bringing improvements in wait() , signal() function. guide other way mentioned below.
you can better achieve using pieterson's solution:-
do{ flag[i]=true; turn = j; while(flag[j] && turn == j); // critical section flag[i]=false; // remainder section } while(true);
this provides better solution bounded waiting. process a[i] can prevented entering critical section if stuck in while loop condition flag[j]==true , turn == j;
-- loop possibility. similarly, every process have respective codes arranged in terms of other process'e execution schedule.
each enter critical section @ time. and, hence, of processes scheduled , execute critical section, unless error occurs deadlock(that other facet).
hence, process can wait maximum n-1
rounds, , provided chance execute critical section --- thereby satisfying bounded waiting. solution case of avoiding race-conditions ----- thereby providing unique registration id each student.
contents taken book operating system concepts(galvin,silberschatz , gagne)
Comments
Post a Comment