Live data from Hacker News

Toothpaste Null-Terminator

dunkels.com

11–20 of 81 posts

Re: Toothpaste Null-Terminator

#12

I don’t understand how this works with systems like toothpaste? I get if you somehow stored your toothpaste in some queue-like structure where you only see 1 at a time, then yes, reaching the last would be helpful. But surely they are in a cupboard or drawer or something? 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…

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

#14
Neat, but I prefer my own method:

1. Have two toothpastes (actually two of everything) 2. When one gets used up, remove the checkmark from my shopping list (just a simple checkmark list on my phone in Google notes) 3. When in the store, buy everything that's not checked on the shopping list

Works all the time, except during the CoVID toilet paper crisis, which made me increase my prepper level to 3 of everything.

Re: Toothpaste Null-Terminator

#15

Am I the only one that has no trouble buying toothpaste when I have to squeeze the tube extra hard?

Many years ago I learned from some Japanese TV show that you can use centrifugal force to get the very last bit of toothpaste out of the tube even if you can’t squeeze out any more. Something similar to this: https://m.youtube.com/watch?v=u-4MKefJqbc

Re: Toothpaste Null-Terminator

#16

I don’t understand how this works with systems like toothpaste? I get if you somehow stored your toothpaste in some queue-like structure where you only see 1 at a time, then yes, reaching the last would be helpful. But surely they are in a cupboard or drawer or something? 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…

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.

Re: Toothpaste Null-Terminator

#17

Am I the only one that has no trouble buying toothpaste when I have to squeeze the tube extra hard?

Not at all. A tube of toothpaste lasts me a long time, and pre-covid I would usually only own one tube a a time.

Post covid I like to keep at least a month stash of anything cheap and durable as toothpaste.

Re: Toothpaste Null-Terminator

#18
The original application of the sentinel technique makes linear search faster.

Looking for 42 in a table of integers? Put 42 after the last element (obviously you need n+1 elements allocated) and your loop does not need to check array bounds, only checking for a[i]==42 is now guaranteed to stop and not read past the array bounds.

(obviously it doesn't work if multiple threads search the same table for different values)

Re: Toothpaste Null-Terminator

#20

Am I the only one that has no trouble buying toothpaste when I have to squeeze the tube extra hard?

Not at all. A tube of toothpaste lasts me a long time, and pre-covid I would usually only own one tube a a time. Post covid I like to keep at least a month stash of anything cheap and durable as toothpaste.

> Post covid I like to keep at least a month stash of anything cheap and durable as toothpaste.

We are a family of 3, and teeth are brushed at least twice a day. 5 tubes of toothpaste would last 6 month. That’s a lot of toothpaste.

Post reply on HN