Part 01 · Revision sheet
Foundations of Computer and Software Systems
Key Terms
- Critical section — code that must run as if no other thread can see it mid-way (→ 7)
- Race condition — unprotected shared mutable state produces timing-dependent, lost or corrupted updates (→ 7)
- Mutex — a lock that makes a critical section exclusive to one thread at a time (→ 7)
- Deadlock — threads frozen forever, each waiting on a resource the other holds (→ 7)
- Concurrency — structuring a program to deal with many in-flight tasks at once (→ 6)
- Parallelism — tasks literally executing at the same instant, requires multiple cores (→ 6)
- Process — the OS's unit of isolation: its own address space (→ 5)
- Thread — a unit of execution sharing memory with sibling threads in a process (→ 5)
- Hash map — get/set in roughly O(1) average time (→ 2)
- Big-O — describes how an operation's cost grows with input size n, not a single measurement (→ 3)
- Stack / heap — stack: automatic and fixed-size per call; heap: flexible, reclaimed manually or by a garbage collector (→ 8)
- Memory hierarchy — CPU cache → RAM → SSD/disk → network, each hop roughly an order of magnitude slower (→ 9)
Decision Rules
- Use the simplest construct that works; avoid abstractions built for imagined future needs (→ 1)
- Pick the data structure whose core operation matches the dominant need; check the cost of every other operation still required before accepting the trade-off (→ 2)
- Classify a snippet's complexity before optimizing, and profile actual load before rewriting for Big-O alone (→ 3)
- Use multiple processes when fault isolation matters; use threads when work needs to share data and isolation isn't required (→ 5)
- Use thread-per-task or a pool for modest concurrency; use an event loop/async for high-concurrency I/O-bound work; use true parallelism only for CPU-bound work (→ 6)
- Synchronize whenever two or more threads read and write the same mutable state; avoid one coarse lock guarding unrelated state (→ 7)
- Accept a garbage collector when developer time matters more than microsecond pause variance; use manual or precise memory control when the language gives you that control and even brief GC pauses are unacceptable (→ 8)
- Optimize the dominant hop (usually network) first; measure where time actually goes before optimizing from the hierarchy alone (→ 9)
Numbers & Formulas
- Growth at n = 1,000: O(1) = 1, O(log n) ≈ 10, O(n) = 1,000, O(n log n) ≈ 10,000, O(n²) = 1,000,000 operations (illustrative) (→ 3)
- Unbounded retention example: 10,000 requests/hour × 1 KB retained/request ≈ 10 MB/hour growth → ≈7.2 GB after 720 hours (30 days) (illustrative) (→ 8)
Traps
- Reaching for a hash map or tree "by default" without checking whether a plain sorted array already meets the need (→ 2)
- Trusting a Big-O classification without multiplying by real call frequency, or optimizing a function that's rarely called (→ 3)
- Treating "garbage collected" as "leak-free" — a held reference leaks in any language (→ 8)
- Inconsistent lock ordering across two code paths producing a deadlock that only appears under load (→ 7)
- Assuming one read() call returns exactly one full request, or blocking accept()/read() on a single thread and serializing every client (→ 10)
Self-Quiz
Mark the questions you can explain and choose which topics to revisit.
Answers are available for this page visit. Browser storage is unavailable.
-
Can you name the dominant operation of a requirement and justify the structure chosen for it? (no → revisit 2)
-
Can you classify an unfamiliar snippet's time and space complexity and state at what input size it becomes a problem? (no → revisit 3)
-
Can you justify, for a given service, whether its workers should be processes or threads? (no → revisit 5)
-
Can you reproduce a lost update, fix it two different ways, and reproduce then fix a deadlock? (no → revisit 7)
-
Can you show unbounded memory growth from a held reference, then eliminate it by bounding the structure? (no → revisit 8)