8 lines
1.3 KiB
HTML
8 lines
1.3 KiB
HTML
<!doctype html><html lang="en"><meta charset="utf-8"><title>Bounded queues and backpressure</title><h1>Bounded queues and backpressure</h1><p>15-minute session: read for 3 minutes, trace for 3, experiment for 7, and complete the check for 2. Spend longer whenever you need.</p><p>An unbounded producer can exhaust memory when consumers are slower. Choose a bounded queue and a policy: wait, reject, or shed selected work. Cancellation and shutdown must wake blocked participants. Model a capacity of two, then explain what happens to a third job and how the caller learns the outcome.</p><p><strong>Practice and evidence:</strong> Predict the example or draw its state transitions. Change one assumption, test the boundary, and record the actual result. Explain what this small model does not establish about a production system.</p><pre><code class="language-python">queue=[]
|
|
capacity=2
|
|
for job in ["A","B","C"]:
|
|
if len(queue)<capacity:queue.append(job)
|
|
else:print("Rejected",job)
|
|
print(queue)
|
|
</code></pre><p><strong>Expected result:</strong> <code>Rejected C
|
|
['A', 'B']</code></p><h3>Practice and evidence</h3><p>Keep three notes: your prediction, the actual result, and why they match or differ. The completion check grades understanding; the practice task builds skill.</p></html> |