Why is the critical-section problem always presented with code in infinite loops? I've noticed that "all" OS textbooks present the Critical-Section Problem with examples of code that are in infinite loops.  E.g.,

while (true) {
    // code here to do the entry section protocol

    // critical section here

    // code here to do the exit section protocol

    // remainder section
}


Why is this?  From my experience there can be many processes that run and enter critical sections (inspecting and updating shared variables) where the code is not in an infinite loop.  This business of always have code in loops seem to unnecessarily complicate matters for students.

Is there something I'm just not understanding about this concept?
One reason infinite loops are used could be so the problem can't be solved by letting one thread complete the code before the other thread starts it. With infinite loops, no thread ever completes the code. Of course, using a bounded buffer has the same effect.