1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Critical section problem

  1. Feb 8, 2013 #1
    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.
     
  2. jcsd
  3. Feb 9, 2013 #2

    rcgldr

    User Avatar
    Homework Helper

    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.
     
  4. Feb 9, 2013 #3
    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?
     
  5. Feb 9, 2013 #4

    rcgldr

    User Avatar
    Homework Helper

    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: Feb 9, 2013
  6. Feb 15, 2013 #5
    Thank You!!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Critical section problem
  1. Method of sections (Replies: 2)

  2. Method of Sections (Replies: 1)

  3. Section modulus (Replies: 1)

Loading...