Hacker News new | ask | show | jobs
by TacticalCoder 671 days ago
> In programming, a sentinel value is a simple way to keep track of the end of a list of items.

A type of sentinels that are cute are "poison pills": when you have a queue and know at some points that no more items are coming, and several consumers, you can simplify the logic by putting as many poison pills at the end of queue as there are consuming threads.

When a consumer finds a poison pill, he stops removing/processing items for the queue.

As there are the same number of poison pills as there are consumers, all consuming threads shall eventually stop.

I probably learned about poison pills back in the days either in Effective Java or in Java Concurrency in practice.