Does this code satisfy mutual exclusion, progress, and bounded waiting?

  • Thread starter Thread starter whitehorsey
  • Start date Start date
  • Tags Tags
    Section
Click For Summary
The code in question fails to satisfy mutual exclusion, progress, and bounded waiting due to its structure, which leads to an infinite loop when both processes execute simultaneously. The discussion highlights that the while loop prevents either process from reaching the critical section, effectively blocking progress. Bounded waiting is uncertain, as there is no defined limit for entering the critical section. Suggestions for improvement include using additional variables or employing algorithms like Dekker's or Peterson's, which are designed for mutual exclusion in concurrent processes. Overall, the code requires significant adjustments to meet the necessary criteria for proper synchronization.
whitehorsey
Messages
188
Reaction score
0
1. Is mutual exclusion, progress, and bounded waiting satisfied in this code?

Code: Two process solution to the critical section problem
code.JPG


For this problem, you can decide any case you want whether the processes go one after the other, execute two lines at once then switch to the other process, etc.

3. This is what I got:
Looking at this code it looks like it will never leave the while loop and hit the critical section so no it does not satisfy mutual exclusion.
Progress can only be made if you hit the critical section since it keeps going around in the while loop then no.
Lastly bounded waiting there is no time limit to enter the critical section? This one I'm not really sure about.
 
Physics news on Phys.org
whitehorsey said:
Looking at this code it looks like it will never leave the while loop.
If you assume that both processes execute in parallel, so that each one executes the same line number at the same time, then you're correct, the code will get stuck in an infinite loop.

Where did you get this example code from? There is code similar to this that will work properly, but I'm not sure if this is homework and you're supposed to fix the code.
 
rcgldr said:
If you assume that both processes execute in parallel, so that each one executes the same line number at the same time, then you're correct, the code will get stuck in an infinite loop.

Where did you get this example code from? There is code similar to this that will work properly, but I'm not sure if this is homework and you're supposed to fix the code.

I got this code while I was surfing the net for examples to practice. I have a test coming up =/
I knew this code would run infinitely but I also don't really understand it. For example, in the while statement (its parentheses) whenever while is whatever the flag is it will always, no matter what enter into that while loop block? If so, when will it ever hit lines 7, 9, 10, and 11?
 
whitehorsey said:
If so, when will it ever hit lines 7, 9, 10, and 11?
Take the case where they both run at the same time and the same line, both run line 0 at the same time, both run line 1 at the same time, ... , both run line 7 at the same time, line 8, and both loop back to line 2 at the same time.

You need at least one more variable or a processor with a special instruction that can load (or test) and store in a single atomic (not interruptable by another process) operation.

If only two processes are running at the same time, Dekker's or Peterson's (these are similar) algorithm can be used. These algorithms won't work on processors that change the order of insructions. Wiki links:

wiki_Dekkers_algorithm.htm

wiki_Petersons_algorithm.htm
 
Last edited:
Thank You!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
1
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
9K