Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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

50%
+0 −0
Q&A How to correctly model the delay timer for a CHIP8 emulator written in C?

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, ...

posted 4d ago by aura-lsprog-86‭

Answer
#1: Initial revision by user avatar aura-lsprog-86‭ · 2025-02-17T07:48:58Z (4 days ago)
_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.