│
▼
Context Switch
│
▼
Thread B
│
├── Instruction X
├── Instruction Y
│
▼
Context Switch
│
▼
Thread A
│
└── Instruction 3
So, the execution timing of a program doesn't depend solely on its own code.
The Scheduler
and the overall system state also influence the scheduling of thread execution.
Process or Thread
There is a crucial point here:
In modern systems, the scheduler typically schedules the entity that actually runs on the CPU at the *thread* level,
rather than always treating the process as an indivisible unit.
For example:
Process A
├── Thread 1
├── Thread 2
└── Thread 3
Process B
├── Thread 1
└── Thread 2
The Scheduler
can select ready threads for execution; this becomes even more significant when we delve deeper into the topic of threads later.
A point regarding CPU Cores:
If we have a single core, only one thread can actually execute on that core at any given moment; however, through rapid switching between threads, it appears as though multiple programs are running simultaneously.
For example:
Time
│
├── Thread A
├── Thread B
├── Thread C
├── Thread A
└── Thread B
If we have multiple cores, multiple threads can actually execute simultaneously on different cores.
This is where the distinction between
Concurrency and Parallelism becomes important.
CPU Scheduling
refers to the kernel deciding which ready thread or process should be allocated the CPU.
Simply put:
Ready
│
▼
Scheduler
│
▼
Running
│
├── Time slice expires
│
▼
Preemption
│
▼
Context Switch
│
▼
Another thread or process
Key concepts in this section:
Scheduler
The component that selects the executable unit.
Ready Queue
The conceptual location for units ready to execute.
Preemption
Taking the CPU away from the currently executing unit.
Timer Interrupt
One of the mechanisms... ...that allow the kernel to check the status and reschedule
Context Switch
Swapping the execution state of the current unit and preparing the next one
Thread
A unit that, in modern systems, is typically scheduled directly for execution
@reverseengine
Post #1821
100
- ❤ 2