Timers are everywhere β from GUIs to embedded systems β but not all C++ frameworks handle them the same way.
If youβve ever tried to find a Windows-like Event/Timer (WM_TIMER message) for Linux, you know the struggle: Qt ties timers to the event loop, POCO has limitations, and standard C++ doesnβt offer true per-thread timers out of the box.
Thatβs where Areg Framework comes in.
Areg delivers per-thread timers that are:
- β Accurate (not bound to GUI refresh rates)
- β Thread-aware (fires in the owning thread)
- β Flexible (one-shot, periodic, cyclic)
π Quick Comparison
Feature | Areg β‘ | Qt QTimer π¨ | POCO Timer βοΈ |
---|---|---|---|
Thread-Aware | β Target thread | β οΈ GUI/event loop needed | β οΈ Callback thread unclear |
Single-Shot/Periodic | β Supported | β Supported | β οΈ Manual setup required |
Cyclic/Repeated | β Until stopped | β Outside GUI limited | β Not native |
Non-Blocking/Queue | β Event queue | β οΈ Event loop only | β οΈ Owner thread unclear |
Central Management | β Timer manager | β Independent timers | β οΈ No central scheduler |
Portability | β Win/Linux | β οΈ Desktop/GUI only | β οΈ Embedded support limited |
π Full Areg timer example here: 08_timer β demonstrates 2 threads with 3 timers each.
Build & run:
git clone https://github.com/aregtech/areg-sdk.git
cd areg-sdk
cmake -B build
cmake --build build -j 12
Run the example binary (replace <compiler>
and <os>-<hw>-<build-type>-<lib-type>
with the real path):
./product/build/<compiler>/<os>-<hw>-<build-type>-<lib-type>/bin/08_timer
β‘ Example: One-Shot, Periodic & Cyclic in Areg
#include "areg/base/Timer.hpp"
class MyTimer : public DispatcherThread, private IETimerConsumer
{
void processTimer(Timer &timer) override {
std::cout << "Timer fired: " << timer.getName() << std::endl;
}
void startTimers() {
mOneShot.startTimer(1000, *this, 1); // One-shot, fires once
mPeriodic.startTimer(2000, *this, 5); // Periodic, fires 5 times
mCyclic.startTimer(3000, *this); // Cyclic, runs until stopped
}
private:
Timer mOneShot{ "OneShot" };
Timer mPeriodic{ "Periodic" };
Timer mCyclic{ "Cyclic" };
};
-
startTimer(timeoutMs, targetThread, 1)
β one-shot -
startTimer(timeoutMs, targetThread, N)
β periodic (N times) -
startTimer(timeoutMs, targetThread)
β cyclic (stops withstopTimer()
)
Simple. Sharp. Reliable.
π― Why care?
- For real-time apps, embedded systems, or distributed services, GUI-based timers (Qt) or non-thread-guaranteed callbacks (POCO) wonβt cut it.
- Areg provides native, thread-level control with minimal code.
β οΈ Note: Windows system timers may have Β± a few ms variation. On Linux, Areg timers are more precise.
π Full working example here: Areg Timer Example.
β Takeaway
If youβve ever wanted Windows-style timers that are cross-platform, accurate, and thread-safe, Areg delivers them out of the box.
Top comments (0)