It helps if you are forgetful in a certain way. If you can remember to buy new toothpaste when you get the last tube out of the drawer, you don;t need a sentinel. But if you forget that the tube you just brought out is your last 5 minutes after you took it out, the sentinel reminds you.
Similarly with the emoji list. If can reliably remember which emoji is last, then each is equally as good as a sentinel. But if you can't, having one which is "special" will help remind you.
I assume OP's solution has thread-safety requirements. The toothpaste may be retrieved from long-term storage by another thread, and that thread may not be configured to check for termination conditions.
Re:Toothpaste Null-Terminator
by alexchamberlain on Saturday August 17, 2024 @02:46PM
(#41276897)
Children act more like separate processes than threads - it would be a miracle if we could read their minds or put them to sleep for a bit.
To know to start the sentinel toothpaste he must search around and prove it’s the only one left - by doing this he doesn’t need the sentinel anyway, as the searching process with yield only one, sentinel or not?
If it doesn’t need a search, e.g. they are in a line/all on easy view - then it’s obvious it’s the last even without a sentinel?