Do not search the heap
transcript
A request is cancelled. Its entry is deep in the heap. Searching costs a lot. There is a better way, and it is cheap.
Every live item keeps an entry. Stale entries wait in the heap. They do no harm while they wait there. The top test removes them.
Leave the entry in place. Mark it as stale. A set of waiting ids does this. Test the entry when it finally reaches the top.
Look at the top entry first. Is it stale? Then pop it. Repeat until the top is live. It must be a loop, not an if. Then read the answer from the top.
Scanning to cancel is slow. It can take five billion comparisons. With marks, about fifty thousand pushes. Each entry leaves at most once, so the work stays small.
Never search the heap. Mark, then test at the top. Full breakdown in the lecture.