How to implement a timer with interruption in C++?

后端 未结 2 1022
攒了一身酷
攒了一身酷 2021-01-07 01:00

I\'m using the GCC compiler and C++ and I want to make a timer that triggers an interruption when the countdown is 0.

Any Ideas? Thanks in advance.

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 01:38

    An easy, portable way to implement an interrupt timer is using Boost.ASIO. Specifically, the boost::asio::deadline_timer class allows you to specify a time duration and an interrupt handler which will be executed asynchronously when the timer runs out.

    See here for a quick tutorial and demonstration.

提交回复
热议问题