Thread_block () is used to terminate current_thread and change it to the blocked state. It cannot be run. It enters the ready queue only after thread_unblock () is called.
Thread_yield () is used to directly put current_thread into the ready queue and can be called again at any time.
List_entry returns a thread.
Idle_thread is usually not in ready_list.
1. In thread_start (), that is, at the beginning of the system, idle_thread is in ready_list.
2. Call idle_thread when ready_list is empty.
Idle () is called at thread_start.
{
1. Set the semaphore whose Initialization is 0 to 1, and put idle_thread into the ready queue.
2. Set the idle_thread status to blocked.
}
Running_thread () returns a running thread
Thread_current () is added with a check running_thread
Init_thread ()
{
1. initialize thread
2. Set status to blocked
3. Reduce the stack space
4. Magic Value
5. Add all_list
}
Next_thread_to_run ()
{
Is the ready queue empty? Return idle_thread: return the first of the ready queue and remove it.
}
Thread_schedule_tail (prev)
{
Thread_tick of current_thread clears 0
Activate Process
If the prev has been dying, it is destroyed.
}
Schedule ()
{
The function called is thread_block, thread_exit, and thread_yield, because the premise is that the current_thread status cannot be running.
}
In conclusion, thread has some external interfaces.
1. thread_create ()
2. thread_block ();
3. thread_unblock ()
4. thread_name ()
5. thread_current ()
6. thread_yield ()
7. thread_set_priority ()
8. next_thread_to_run ()