李秀景整容,超级演说家 林志颖,吉吉影音av
系统创建新线程时,会同时创建与这个线程相关联的队列,即异步过程调用(apc)的队列。
一些异步操作可以通过加入apc来实现,比如我现在学习的io请求/完成。
bool readfileex( handle hfile, lpvoid lpbuffer, dword nnumberofbytestoread, lpoverlapped lpoverlapped, lpoverlapped_completion_routine lpcompletionroutine );
io完成时,系统向该线程的apc队列中加入一项,包含lpcompleteionroutine和lpoverlapped。当线程处于非执行态且是可提醒的状态时,系统会取出apc中的项,并让线程执行其中的回调函数。这个动作会重复到队列空,我猜想可能还会被线程正常唤醒打断。
非执行态是线程调用了等待、休眠函数,像
dword sleepex(dword dwmilliseconds, bool balertable );
dword waitforsigleobjectex(handle hobject,dword dwmilliseconds,bool balertable);
balertable=true; 是可提醒状态!
另一段apc call的代码,是一个waitabletimer的例子。
#include <iostream> #include<process.h> #include<windows.h> #include<tchar.h> #include<string.h> void apientry timerapcroutine(pvoid pvargtocompleteroutine, dword dwtimerlowvalue, dword dwtimerhighvalue); void somefunc() { handle htimer = createwaitabletimer(null, true, null); large_integer li = { 0 }; setwaitabletimer(htimer, &li, 5000, timerapcroutine, null, false); sleepex(infinite, true); closehandle(htimer); } void apientry timerapcroutine(pvoid pvargtocompleteroutine, dword dwtimerlowvalue, dword dwtimerhighvalue) { filetime ftutc, ftlocal; systemtime st; tchar szbuf[256]; ftutc.dwhighdatetime = dwtimerhighvalue; ftutc.dwlowdatetime = dwtimerlowvalue; filetimetolocalfiletime(&ftutc, &ftlocal); filetimetosystemtime(&ftlocal, &st); getdateformat(locale_user_default, date_longdate, &st, null, szbuf, _countof(szbuf)); _tcscat_s(szbuf, _countof(szbuf), " "); gettimeformat(locale_user_default, 0, &st, null, _tcschr(szbuf, text('\0')), (int)(_countof(szbuf) - _tcslen(szbuf))); messagebox(null, szbuf, text("timer went off at ..."), mb_ok); } int wmain(int argc, wchar_t* argv[]) { somefunc(); char c; std::cin >> c; return 0; }
线程跑到apc回调函数时,
apc是由系统管理的与线程相关的队列,可用来执行异步操作。
apc的回调函数是在原线程休眠时在原线程上调用。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新补丁让Windows 10出现死机、卡顿等 微软坐不住称正解决
Ubuntu 20.04 LTS进驻Windows子系统:只能用3年
ThinkPad正式加入:预装Linux发行版而非Win10的PC越来越多了
最新版Android 11推送!谷歌Pixel 5被曝光:支持反向充电
高度致敬Windows!开源优麒麟20.04 LTS发布:支持5年
电脑小知识:Windows 10是用什么语言写的?到底有多少行代码?
Win10 5月更新准正式版:微软引入大量新功能 系统响应速度快
Windows 10新预览版19613推送:修复任务栏图标显示异常BUG
Windows AD 报错解决:UAC File Virtualization服务启动失败 此驱动程序被阻止加载
网友评论