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
SUMMARY

The discussed code fails to satisfy mutual exclusion, progress, and bounded waiting in a two-process solution to the critical section problem. The infinite loop caused by the while statement prevents either process from entering the critical section, confirming that mutual exclusion is not achieved. Progress is hindered as the processes remain stuck in the loop, and bounded waiting is not applicable due to the lack of a time limit for entering the critical section. Alternative algorithms such as Dekker's or Peterson's can be utilized to address these issues effectively.

PREREQUISITES
  • Understanding of critical section problems in concurrent programming
  • Familiarity with mutual exclusion, progress, and bounded waiting concepts
  • Knowledge of Dekker's and Peterson's algorithms
  • Basic understanding of atomic operations in multi-threading
NEXT STEPS
  • Study Dekker's algorithm for mutual exclusion in concurrent processes
  • Learn about Peterson's algorithm and its implementation
  • Explore atomic operations and their role in preventing race conditions
  • Research the concept of semaphore and its application in process synchronization
USEFUL FOR

Students preparing for exams in operating systems, software developers working on concurrent programming, and anyone interested in understanding process synchronization techniques.

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