Tip

While pre-emption was covered, for the most part it wasn’t that relevant. I wouldn’t dive too deep into it.

Pre-emption occurs when a yield is forced upon the current running thread. Current thread is stopped, made runnable not blocked, to allow another thread to run.

Some types of pre-emption are:

Priority-based Pre-emption

CPUs have to decide what threads to run at what point in time when multiple processes are asking for them. This is the topic behind CPU scheduling, which is a super interesting topic but is almost entirely out of the scope of 213.

One interesting part of it, is that sometimes CPU schedulers will give a certain priority to threads to decide which threads to run first. In some Linux implementations, I believe this is called niceness (as in the niceness to yield to other threads).

So the CPU will decide what thread to run not based on which one got to acquire a spot on a core first, but rather on how important they are. In some cases then, the CPU can force a thread to yield by pre-empting it to let a thread of higher priority run.

Quantum-based Pre-emption

Quantum-based pre-emption is mentioned in the slides as a thread being assigned a runtime clock (or quantum) and yielding at the end of its clock. This sounds a lot like time-slicing to me, and when looking it up I could not find many resources about ‘quantum based pre-emption’, in fact the first result were the CPSC 213 slides. Makes me think that this just an alias for time-slicing? Not sure though.