C++ Logo


Advanced search

Re: Proposal : std::timer

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Sat, 11 Jan 2020 11:24:57 -0500
On Fri, Jan 10, 2020 at 6:28 PM contact--- via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hello,
> I hope you're well and you enjoy 2020. I'm writing you a short message
> about a C++ proposal. Of course, the C++ is my favorite programming
> language and I have an idea about a new std class or struct that doesn't
> yet exist. I think it could be cool to have a std::timer similar to the
> win32 timer (
> https://docs.microsoft.com/en-us/windows/win32/winmsg/using-timers) or
> the qt timer (https://doc.qt.io/qt-5/qtimer.html) or the GLUT timer (
> https://linux.die.net/man/3/gluttimerfunc) or ...
> The implementation can be discuted of course. It can use std::chrono,
> std::thread, std::function and more.
> This is a draft.
> namespace std
> {
> class timer
> {
> public:
> timer(); // constructor
> thread to use for the call of the callback
> timer(); // will call the callback on the main thread (or
> the thread where the timer has been constructed)
> timer(thread_id); // will use this thread_id for the call of
> the callback

How would you expect this to work? If you provide the thread_id of an
existing thread, then the timer can't call its callback "on that thread"
because that thread is already doing its own thing. And if you provide the
thread_id of a non-existent thread, that doesn't seem useful.

I recommend starting with an *implementation* of the facility that you can
actually use in your own code, and then, if it proves useful, then worry
about porting it to other platforms; and finally, if you find that you need
a standard to iron out unintentional differences between your
implementations on different platforms, *that's* the time to think about


Received on 2020-01-11 10:27:41