# K12 — Semaphores and task notifications ## Position - Series: FreeRTOS C++ - Lesson: L11, card K12 - Duration: 30 minutes - Waiter priority 3, signaler priority 2 - Static semaphore controls; notification state in waiter TCB ## Outcome The student selects a binary semaphore, counting semaphore or direct task notification from the communication cardinality and state semantics, then proves blocked/wake transitions and clear/value policy. ## Lesson plan | Time | Mode | Evidence | | --- | --- | --- | | 0–5 | binary | empty 0, give 1, second give false, take 0 | | 5–10 | counting | max/initial 2, take to 1 then 0 | | 10–15 | blocked waiter | third take blocks; signaler observes eBlocked | | 15–20 | release | one give wakes exactly one waiter; token consumed | | 20–25 | notification count | give/take returns 1, state lives in TCB | | 25–30 | notification value | explicit overwrite/wait yields 0xA5A55A5A | ## Acceptance - binary and counting bounds are enforced; - both handles equal caller static controls and heap delta is zero; - waiter is blocked at all three intended waits; - counting release is consumed immediately, leaving count 0; - notification give/take returns exactly 1; - explicit `overwrite` action transfers 0xA5A55A5A; - event order connects counting block/release and both notification phases; - target exits with PASS. ## Main traps 1. A semaphore signals availability; it does not carry a data record. 2. Notification targets one specific task/slot, not arbitrary consumers. 3. Clear-on-exit versus decrement changes binary/counting notification meaning. 4. Wrong action or clear mask can silently lose bits/value. 5. Identical wake behavior does not imply identical storage/cardinality.