Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I received this answer in SE. Sadly, the user who wrote the answer is no longer in the site. Don't use threads and synchronization primitives (semaphores, shared memory, etc) for this. In fact, ...
Answer
#1: Initial revision
_I received [this answer](https://stackoverflow.com/a/38340293/5397930) in SE. Sadly, the user who wrote the answer is no longer in the site._ <hr /> Don't use threads and synchronization primitives (semaphores, shared memory, etc) for this. In fact, I'd go as far as to say: don't use threads for _anything_ unless you explicitly need multi-processor concurrency. Synchronization is difficult to get right, and even more difficult to debug when you get it wrong. Instead, figure out a way to implement this in a single thread. I'd recommend one of two approaches: 1. Keep track of the time the last value was written to the timer register. When reading from the register, calculate how long ago it was written to, and subtract an appropriate value from the result. 2. Keep track of how many instructions are being executed overall, and subtract `1` from the timer register every `N` instructions, where `N` is a large number such that `N` instructions is about `1/60` second.