This is a example about using counter to build something useful like a clock. Inspired by cprogramming.com
The counter stores a value that can be
decremented in a multithread safe way realized with an
A modcounter is s modulo
n counter. Example
n = 3
|x||x % n|
|See the pattern? It's
Let's transfer this to the time. A minute consists of 60s - after the 59th second the counter starts from 0 again.
So obviously this is the same as
f(t) = t % 60.
The visualization shows the seconds, minutes and hours over 61 minutes in seconds.
After 60s a minute passed. So it's the same principle for the minutes. After 60 minutes a hour passed. After 24 hours a day passed. So we have some kind of carry for each unit if it resets to 0. We need to carry the next bigger unit.
A linked modulo counter is capable to handle this carry. It knows his next bigger unit. Putting multiple counters in a row we can call this a cascade.