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

  • Thread starter whitehorsey
  • Start date
  • Tags
    Section
In summary, the conversation discusses a code for a two process solution to the critical section problem and whether it satisfies mutual exclusion, progress, and bounded waiting. The code does not satisfy mutual exclusion as it will never leave the while loop and enter the critical section. Progress can only be made if the critical section is reached, and there is no time limit for entering the critical section, so bounded waiting is not satisfied. The code was found online and the person is unsure if it is for a homework assignment. They also mention that the code can be fixed by adding another variable or using a processor with a special instruction. Two algorithms, Dekker's and Peterson's, are suggested for solving the problem.
  • #1
whitehorsey
192
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
  • #2
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.
 
  • #3
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?
 
  • #4
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:
  • #5
Thank You!
 

What is the Critical Section Problem?

The Critical Section Problem is a classic synchronization problem in computer science that occurs when multiple processes or threads try to access and modify a shared resource concurrently. It is a fundamental issue in operating systems and distributed systems.

What is the purpose of solving the Critical Section Problem?

The purpose of solving the Critical Section Problem is to ensure that only one process or thread can access the shared resource at a time, preventing any conflicts or data inconsistencies. This helps to maintain the integrity and consistency of the shared resource.

What are the three main requirements for a solution to the Critical Section Problem?

The three main requirements for a solution to the Critical Section Problem are mutual exclusion, progress, and bounded waiting. Mutual exclusion ensures that only one process can access the shared resource at a time. Progress ensures that if a process is not in its critical section, it cannot block other processes from entering their critical sections. Bounded waiting ensures that no process is left waiting indefinitely to enter its critical section.

What are some common approaches to solving the Critical Section Problem?

Some common approaches to solving the Critical Section Problem include using semaphores, monitors, and locks. These mechanisms provide a way for processes to synchronize their access to the shared resource and ensure that only one process can access the resource at a time.

What are some potential issues that can arise when solving the Critical Section Problem?

Some potential issues that can arise when solving the Critical Section Problem include deadlock, starvation, and busy waiting. Deadlock occurs when two or more processes are waiting for each other to release the shared resource, causing them to get stuck indefinitely. Starvation occurs when a process is constantly denied access to the shared resource. Busy waiting occurs when a process continuously polls for the availability of the shared resource, wasting CPU time.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
8
Views
878
  • Quantum Physics
5
Replies
143
Views
6K
Back
Top