Concurrency (并发)


Quote

Concurrency is about dealing with lots of things at once, but parallelism is about doing lots of things at once.

  • A way to run multiple Thread at the same time, instead of running one thread after another thread is done . Thus, improving the overall performance
  • Can be achieved with multiple Core(Parallelism (并行性)) or Context Switch when there is only one core

Resource utilisation

Maximise the use of resources on hand and handle multiple requests or events.

Time-Sharing


Info

Multics - Wikipedia was one of the first time-sharing OS which inspires the creation of Unix.

Parallelism (并行性)


Corporative Scheduling


CPU Hogging

Process can hog to CPU forever, modern OS adapts Preemptive Scheduling instead.

Preemptive Scheduling


  1. Before jumping to program code, the Kernel sets the Timer Chip to trigger an Hardware interrupts (外中断) after some period of time
  2. The kernel switches to User Mode and jumps to the next Instruction of the program
  3. When the Timer Chips elapses, it triggers a Hardware interrupts. The CPU receives the interrupt.
  4. The hardware interrupt stores Program Counter, so it can resume later
  5. The hardware interrupt invokes corresponding Interrupt Handler
  6. Interrupt passes control to Process Scheduler selects a process to run by restoring the state of the CPU for that process from the process’s PCB
  7. Repeat step 1 to step 7

No CPU Hogging

Ensure no Process (进程) can hog the CPU forever.

References