Implementing an event timer using boost::asio

后端 未结 3 810
暖寄归人
暖寄归人 2021-01-24 15:42

The sample code looks long, but actually it\'s not so complicated :-)

What I\'m trying to do is, when a user calls EventTimer.Start(), it will execute the callba

3条回答
  •  心在旅途
    2021-01-24 16:28

    As Sam hinted, depending on what you're attempting to accomplish, most of the time it is considered a design error to stop an io_service. You do not need to stop()/reset() the io_service in order to reschedule a timer.

    Normally you would leave a thread or thread pool running attatched to an io_service and then you would schedule whatever event you need with the io_service. With the io_service machinery in place, leave it up to the io_service to dispatch your scheduled work as requested and then you only have to work with the events or work requests that you schedule with the io_service.

提交回复
热议问题