Files
2026-07-21 19:14:19 +02:00

47 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# K10 — Queue<T> and StaticQueue<T, N>
## Position
- Series: FreeRTOS C++
- Lesson: L09, card K10
- Duration: 30 minutes
- Platform: Hazard3 / RV32I, FreeRTOS V11.3.0
- Message: 12-byte trivial `Sample`, capacity 2
## Outcome
The student explains byte-copy semantics, designs a trivial message, proves a
copy survives source mutation, compares dynamic and caller-owned static queue
storage, and handles full/empty states with explicit bounded timeouts.
## Lesson plan
| Time | Mode | Evidence |
| --- | --- | --- |
| 05 | type contract | `Sample` passes; owning `VectorV1` fails |
| 510 | create | dynamic cost 128 B; static delta 0 B |
| 1015 | copy | send, mutate source, receive unchanged copy |
| 1520 | storage | inspect first 12 static storage bytes |
| 2025 | full/timeout | capacity 2; third send fails after 2 ticks |
| 2530 | FIFO/drain | values 0x2222 then 0x3333; empty receive fails |
## Acceptance
- `sizeof(Sample)==12` reaches both create APIs;
- dynamic cost is positive and recovered by RAII destruction;
- static create has zero heap delta and its buffers are in `.bss`;
- received value remains 0x1111 after source becomes 0xDEAD;
- storage snapshot equals the first sent `Sample` byte-for-byte;
- full count is 2, third send returns false after at least 2 ticks;
- FIFO and non-blocking empty receive are correct;
- non-trivial owning message fails for the pinned static-assert reason;
- target exits with PASS.
## Main traps
1. Queue storage is a byte copy, not a C++ object owner.
2. `sizeof(pointer)` plus an object address is a different and invalid contract.
3. A trivially-copyable pointer still needs an external lifetime policy.
4. `portMAX_DELAY` must not be hidden as a convenient default.
5. Static queue control and byte storage must both outlive the queue.