I am learning operating systems through an online course and I came across some software solutions for Process Synchronization. The teacher is explaining all software solutions starting from using a single turn
variable upto Peterson's solution.
I have a doubt in the most basic approach. Please refer to the attached screenshot from the course video for clarity. The approach is to use a single turn
variable in case of two processes and store 1 or 2 in turn depending on which process wants to access the critical section. This approach guarantees mutual exclusion but does not satisfy the progress requirement because if turn
is 1 initially and P2 wants to enter the critical section first then it will be simply blocked waiting in the while loop even though P1 is not in the critical section. My idea is to initiate turn
as -1 and now proceed. No process will be blocked depending on other then.
I have checked multiple online courses but no one is discussing this simple change and rather moving on to advanced solutions like Petersons algorithm or semaphores. Am I thinking right? Is my approach correct?