• 浅析boost::asio::deadline_timer运行机制


    在使用到deadline_timer时,我需要同时使io_serivice的post函数以及使用timer的async_wait,但是我不清楚async_wait是否准确地在它等待的时刻进行回调。于是我做了一个实验。

        在windows下,io_service的实现是win_iocp_io_service,win_iocp_io_service使用了ICOP实现异步机制。win_iocp_io_service的post函数最终是使用PostQueuedCompletionStatus处理,好比是直接加入了待运行列表,而boost::asio::deadline_timer的机制就稍复杂,boost::asio::deadline_timer需要一个io_service做为参数,并且会使用这个参数来构建一个deadline_timer_service,deadline_timer_service里有一个timer_queue_用来储存所有的timer,并且在deadline_timer_service构造时会将timer_queue_使用io_service::add_timer_queue传入win_iocp_io_service。在win_iocp_io_service的do_one中会查询所有的timer_queue_,并且判断其中的timer是否到期,如果到期则将其中的函数对象加入待运行列表。
        所以在上例中,无论 t.async_wait(handler)在哪里调用,handler都会比其它的使用post传入handler晚调用,原因是service运行时post传入的handler已经在运行队列中了,等到timer到期时,t.async_wait传入的handler被加在了队尾,所以t.async_wait(handler)中handler被调用的时间应该是timer的时间+timer到期时整个命令序列执行时需要的时间长度。

  • 相关阅读:
    查看SQL Server版本号(2005 & 2008)
    Installing an App for Testing
    Viewstate 的用法
    How to Open the Pdf file?
    工具类:Log
    SPSiteDataQuery and SPQuery
    SPSite, SPWeb Dispose and Class Design Partter
    Add Properties or Delete List Folder Content Type
    SharePoint UserControl
    Click Once 布署
  • 原文地址:https://www.cnblogs.com/k1988/p/2165652.html
Copyright © 2020-2023  润新知