timer class in linux

后端 未结 5 1604
清歌不尽
清歌不尽 2021-02-04 22:27

I need a timer to execute callbacks with relatively low resolution. What\'s the best way to implement such C++ timer class in Linux? Are there any libraries I could use?

5条回答
  •  故里飘歌
    2021-02-04 22:59

    The timeval struct from the time.h header is what you are looking for. It has time in seconds and nanoseconds. So total time in nanoseconds is timeval.tv_sec * 1000000 + timeval.tv_usec. Easy enough, I think.

    #include 
    timeval theStartTime;
    gettimeofday(&theStartTime);
    std::cout<<"The time we got's seconds field = "<
                                                            
提交回复
热议问题