Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:56:41+00:00 2026-06-12T22:56:41+00:00

Okay, i was reading the critical section problem from galvin’s sixth edition. Thing is,

  • 0

Okay, i was reading the critical section problem from galvin’s sixth edition. Thing is, the algorithm used in the problem has a while loop as:

do
  {
   while(turn!=i);
   critical section
   turn=j;
    remainder section
}while(1);

Initially turn==0 and for i=0, process p0 runs its critical problem. The while(turn!=i); evaluates to while(false) for this particular case.

Now my question is if the while loop evaluates to false how come the following critical section is evaluated. And here comes the stupid part, if for any reason the while(turn!=i); has a semicolon then the following statements have no effect of the while loop! So, whats the use of the while loop in here!? 😐

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:56:43+00:00Added an answer on June 12, 2026 at 10:56 pm

    In this case, the while loop will either loop infinitly, either do nothing. The while loop with a semi-colomn specifies that it should try to loop, but with no instruction being executed in the while block. Writing while (1); is equivalent to while (1) {}

    A common usage of this syntax is when you just want to iterate, let say, until the end of string, to futher work. You would write something like

    char *work_on_end_of_string(char *str) {
      int i = 0;
    
      while (str[i++]); 
      // now str[i] is pointing on the end of the string
    }
    

    In your case, as you mentionned that your program was multithreaded, turn or i seems to need to be different before executing the critical section. The while statement enable to loop on testing this condition, until a thread modify one of those to satisfy it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so I am reading in a bunch of information from a file about
Okay, to get a reasonable picture of what's happening... I'm reading the data from
Okay I hear that thing all the time on internet when reading an article
Okay so I need help understanding something. I understand how ? : are used
I have been reading the code used by R to fit a generalized linear
I have a problem with reading empty string in C. I want to read
Okay I am officially confused. I'm reading up on this MVC intro in php
Okay so ive been reading up on and working with SQLite recently (someone on
Okay, I've been reading and searching around, and am now banging my head against
Okay, I've been reading about rvalues and they seem like a great idea, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.