Quote:
p1 can enter the critical section under two conditions. Firstly, flag[2] could be false. If so p2 will set the turn to 1, and since p1 has set flag[1] to true p2 will not be able to enter the CS until p1 sets flag[1] to false (after it has exited the CS). Secondly, turn could equal 1. If so , since p1 has set flag[1] to true, p2 cannot enter the CS. It will have to wait until p1 sets flag[1] to false
Quote:
The two cannot enter the CS at the same time. Even if both flags are set, turn will only allow one to enter at a time. The blocked process must wait until the running process either exits the CS and sets its flag to false, or until it changes turn
Quote:
p2 cannot set the values equal to what p2 needs to enter, only p1 can. Only p1 can turn flag[1] to false, and only p1 can set turn to 2
Quote:
If a low priority process has a resource that a high priority process needs, the higher priority process simply must wait until the resource is relinquished. There are ways to avoid priority inversion, but there is no safe way to force a process to give up a resource after it has started using it and before it has finished.
Originally Posted by mothergoose729 ![]() My question is, what stops P2 from entering the CS while P1 is currently within the CS process? |
Quote:
What stops P2 from following P1 into the CS almost instantly after p1 and executing a critical process and producing an error? |
Quote:
Won't P2 set the values equal to what it needs to enter the CS while P1 is executing, and assuming execution takes longer then changing values, couldn't that have issues? |
Quote:
A more advance question, what if P2 is of hire priority to the system user(s) but P1 is able to execute the values of turn and flag first. How does the OS address that problem? |