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

Discussion Overview

The discussion revolves around the evaluation of a code snippet related to the critical section problem, specifically addressing whether it satisfies the conditions of mutual exclusion, progress, and bounded waiting. Participants explore the implications of the code's structure and behavior in a theoretical context.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant asserts that the code does not satisfy mutual exclusion, claiming it will never leave the while loop to enter the critical section.
  • Another participant agrees that if both processes execute in parallel, the code could get stuck in an infinite loop, questioning the source of the example code.
  • A participant expresses uncertainty about the code's behavior, particularly regarding the while statement and its impact on reaching subsequent lines of code.
  • It is suggested that additional variables or atomic operations are necessary for proper execution, referencing Dekker's and Peterson's algorithms as potential solutions.

Areas of Agreement / Disagreement

Participants generally agree that the code may lead to an infinite loop under certain assumptions about process execution. However, there is no consensus on the specific conditions under which mutual exclusion, progress, and bounded waiting are satisfied or violated.

Contextual Notes

Participants note the importance of assumptions regarding process execution and the potential need for additional mechanisms to ensure proper functioning of the code. There are references to specific algorithms that may address the issues raised, but their applicability is not universally accepted.

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
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
9K