is there a way to have a callback-based timer in c++ that works both in winblows and poosix without having to write specific code for each
Follow

@tuxcrafting if you're not afraid of threads (which you should be) there are ways. Your timer could be a thread that sleeps for/until certain time and then calls back.
If need a ton of timers, maybe better to set up an update loop, that every "min_timer_duration" advances all timers (that are just durations) and invokes the callbacks of those that expire. Doing this on main thread you can almost get away without concurrency, but unfortunately still need at least one other thread to handle IO, cause it's blocking.
Then go down the rabbit hole.

· · SubwayTooter · 0 · 0 · 1
Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.