operating system - Difficulty in understanding Petersons Algorithm -


i having bit difficulty understanding peterson's algorithm: algorithm says:

flag[i] = true; turn = j; while (flag[j] && turn == j); // critical section ... // end of critical section flag[i] = false; 

now lets suppose flag[0]=flag[1]=true

if p1 starts executing, busy waiting @ while loop since flag[0] , turn==0 both true. if p0 not want execute, p1 never execute critical section.

please clear doubt;there may gaps in understanding.

thanks

now lets suppose flag[0]=flag[1]=true

now if p0 not want execute, p1 never execute critical section.

both flags should initialized false. way both set true if both processes want execute or executing critical section. therefore if p1 waiting execute, flag[0] true, p0 must either execute critical section, or in middle of executing it, after flag[0] set false , p1 can enter critical section. also, if p1 waiting execute, p0 cannot waiting execute, because waiting conditions mutually exclusive (since turn either 0 or 1 , cannot both simultaneously).

initializing both flags true can lead deadlock describe. doing makes no sense, since meaning of flags indicate process wants enter critical section, if that's not case, why set value?


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -