-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Lession4] schedule function explanation seems incorrect #212
Comments
Fairly old post, but the explanation is correct. Since c = -1, the if statement containing the break will not execute and it will fall through to the second for loop. Normal case is that some process will have a counter value of 1 or more and will have the running state (as of this lesson). In this case, this will be the chosen task, and we will switch to it. In the case that all processes are waiting for an interrupt, the statement: "if (p && p->state == TASK_RUNNING && p->counter > c)" will never be true . Therefore, c will remain -1 and "if (c)" will be false and we will fall through to the second for loop. There is also the case where all tasks have counter of 0, and as the paragraph mentions, the second for loop will increase their counter within their priority range. We will stay in the while loop until at least on task has a state RUNNING. |
I know this is an old response now, but I am responding because I have the same question as the op. |
You're correct. After quickly testing it myself I believe there is an error in the description as @drymon mentioned. |
Someone can you please help me to understand this explaination of the _schedule?
My understanding is if all task are waiting for an interrupt, after the first for loop, 'c'=-1 and the if(c){break} will break the while loop and the second for loop will not be executed.
If my understanding is correct, the above explanation should be corrected.
I pasted the function here for convenient:
The text was updated successfully, but these errors were encountered: