0
Challenge · 86CS Fundamentals

Process vs thread

OSused in ~93% of apps

The most reliably asked operating systems question, and the one most often answered with a memorised sentence about lightweight processes. What the interviewer wants is the consequence: what is shared, and therefore what can go wrong.

Core idea. A process is a running program with its own memory. A thread is a path of execution inside a process, and all threads in a process share that memory. Every difference between them, in cost, in isolation, and in the bugs they produce, follows from that one fact.
Playground, this isn't a screenshot
tick the behaviours an item needs
with inheritance
class PlainItem
One class per combination. Three behaviours need 8 classes, and a fourth needs 16.
with composition
traits: []
One item, a list of behaviours. Three behaviours need 3 functions, and a fourth needs 4.

Inheritance grows as two to the number of behaviours. Composition grows as the number of behaviours.

↑ play a little first, then dig in