| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> delphi >> WIN32 xia DELPHI zhong de duo xian cheng 【 xian cheng de tiao du 】( er )

WIN32 xia DELPHI zhong de duo xian cheng 【 xian cheng de tiao du 】( er )

2006-12-12 19:18:06 编辑來源:互联网 评论
 
 
 
本文为【WIN32下DELPHI中的多线程【线程的调度】(二)】的拼音翻译版
  xian cheng de tiao du
   mei ge xian cheng shi yong you yi ge shang xia wen jie gou de , zhe ge jie gou wei hu zai xian cheng de nei gai dui xiang zhong 。 zhe ge shang xia wen jie gou fan yang le xian cheng shang ci yun xing shi gai xian cheng de C P U ji cun qi de zhuang tai 。 mei ge 20ms zuo you ,Windows yao cha kan dang qian cun zai de suo you xian cheng nei gai dui xiang 。 zai zhe xie dui xiang zhong , zhi you mou xie dui xiang bei shi wei ke yi tiao du de dui xiang 。Windows xuan ze ke tiao du de xian cheng nei gai dui xiang zhong de yi ge , jiang ta jia zai dao C P U de ji cun qi zhong , ta de zhi shi shang ci bao cun zai xian cheng de huan jing zhong de zhi 。 zhe xiang cao zuo cheng wei shang xia wen zhuan huan 。Windows shi ji shang bao cun le yi ge ji lu , ta shuo ming mei ge xian cheng huo de le duo shao ge yun xing ji hui 。
   Windows bei cheng wei qiang zhan shi duo xian cheng cao zuo xi tong , yin wei yi ge xian cheng ke yi sui shi ting zhi yun xing , sui hou ling yi ge xian cheng ke jin xing tiao du 。 ru ni suo jian , ke yi dui ta jin xing yi ding cheng du de kong zhi , dan shi bu neng tai duo 。 zhu yi , wu fa bao zheng xian cheng zong shi neng gou yun xing , ye bu neng bao zheng xian cheng neng gou de dao zheng ge jin cheng , wu fa bao zheng qi ta xian cheng bu bei yuan xu yun xing deng deng 。
   wo zai bian xie chuan kou tong xun cheng xu de shi hou , qi chu , wo you yi ge tian zhen de xiang fa ,“ zai win32 ping tai xia , ru he neng gou bao zheng cong chuan kou chuan song guo lai de shu ju , zai shu ju dao da hou 1MS nei kai shi yun xing ?”。 wei ci , wo zeng jing zuo le xu duo shi yan , dan dang wo zhen zheng le jie le yi xie win32 ping tai de zhi shi , wo de dao le da an , ban bu dao 。 zhi you shi shi cao zuo xi tong cai neng zuo chu zhe yang de cheng nuo , dan Windows bu shi shi shi cao zuo xi tong 。 shi shi cao zuo xi tong bi xu qing chu di zhi dao ta shi zai shen me ying jian shang yun xing , zhe yang ta cai neng zhi dao ta de ying pan kong zhi qi he jian pan deng de deng dai shi jian 。Microsoft dui Windows gui ding de mu biao shi , shi ta neng gou zai ge zhong bu tong de ying jian shang yun xing , ji neng gou zai bu tong de CPU、 bu tong de qu dong qi he bu tong de wang luo shang yun xing 。 jian er yan zhi ,Windows mei you she ji cheng wei yi zhong shi shi cao zuo xi tong 。
   Windows xi tong zhi tiao du ke yi tiao du de xian cheng 。 na me shen me shi ke yi tiao du de xian cheng , shen me shi bu ke yi tiao du de xian cheng ne ? li ru , you xie xian cheng dui xiang de zan ting ji shu da yu 1( ji lu zai xian cheng nei gai dui xiang de shang xia wen jie gou zhong )。 zhe yi wei zhe gai xian cheng yi jing zan ting yun xing , bu ying gai gei ta an pai ren he C P U shi jian 。 huan ji de shang wen zhong zeng jing ti dao de CREATE_SUSPENDED biao zhi ma ? zai chuang jian yi ge xian cheng de shi hou ,createThread han shu jie shou de dao shu di er ge shen shu zhong fu zhi CREATE_SUSPENDED jiu ke yi chuang jian yi ge zan ting de xian cheng 。 chu le zan ting de xian cheng wai , qi ta xu duo xian cheng ye shi bu ke tiao du de xian cheng , yin wei ta men zheng zai deng dai mou xie shi qing de fa sheng 。 li ru , ru guo ji shi ben cheng xu , ru guo ni bu jian ru ren he shu ju , na me ta de xian cheng jiu mei you shen me shi qing yao zuo 。 xi tong bu gei wu shi ke zuo de xian cheng fen pei CPU shi jian 。 dang yi dong ta de chuang kou shi , huo zhe ta de chuang kou xu yao shua xin ta de nei rong , huo zhe jiang shu ju jian ru ji shi ben , xi tong jiu hui zi dong shi ta de xian cheng cheng wei ke tiao du de xian cheng 。 dan qie ji , zhe bing bu yi wei zhe ta de xian cheng li ji huo de le CPU shi jian 。 ta zhi shi biao shi ji shi ben de de xian cheng you shi qing ke zuo , xi tong jiang she fa zai mou ge shi jian ( bu jiu de jiang lai ) dui ta jin xing tiao du 。
  xian cheng de zan ting he zhi xing
   wo men qian mian shuo guo , zai xian cheng nei gai dui xiang de nei bu you yi ge zhi , yong yu zhi ming xian cheng de zan ting ji shu 。 dang tiao yong CreateThread han shu shi , jiu chuang jian le xian cheng de nei gai dui xiang , bing qie ta de zan ting ji shu bei chu shi hua wei 1。 zhe ke yi fang zhi xian cheng bei tiao du dao CPU zhong 。 dang ran , zhe shi hen you yong de , yin wei xian cheng de chu shi hua xu yao shi jian , ni bu xi wang zai xi tong zuo hao chong fen de zhun bei zhi qian jiu kai shi zhi xing xian cheng 。 dang xian cheng wan quan chu shi hua hao le zhi hou , yao cha kan shi fou yi jing chuan di le CREATE_SUSPENDED biao zhi 。 ru guo yi jing chuan di le zhe ge biao zhi , na me zhe xie han shu jiu fan hui , tong shi xin xian cheng chu yu zan ting zhuang tai 。 ru guo shang wei chuan di gai biao zhi , na me gai han shu jiang xian cheng de zan ting ji shu di jian wei 0。 dang xian cheng de zan ting ji shu shi 0 de shi hou , chu fei xian cheng zheng zai deng dai qi ta mou zhong shi qing de fa sheng , fou ze gai xian cheng jiu chu yu ke tiao du zhuang tai 。
   zai zan ting zhuang tai zhong chuang jian yi ge xian cheng , jiu neng gou zai xian cheng you ji hui zhi xing ren he dai ma zhi qian gai bian xian cheng de yun xing huan jing ( ru you xian ji )。 yi dan gai bian le xian cheng de huan jing , bi xu shi xian cheng cheng wei ke tiao du xian cheng 。 yao jin xing zhe xiang cao zuo , ke yi tiao yong ResumeThread, jiang xian cheng ju bing chuan di gei ta , ru guo ResumeThread, han shu yun xing cheng gong , ta jiang fan hui xian cheng de qian yi ge zan ting ji shu , fou ze fan hui 0xFFFFFFFF。 zhu yi zhe li , ta fan hui de shi qian yi ge zan ting ji shu 。
   dan ge xian cheng ke yi zan ting ruo gan ci 。 ru guo yi ge xian cheng zan ting le 3 ci , ta bi xu hui fu 3 ci , ran hou ta cai ke yi bei fen pei gei yi ge C P U。 dang chuang jian xian cheng shi , chu le shi yong CREATE_SUSPENDED wai , ye ke yi tiao yong SuspendThread han shu lai zan ting xian cheng de yun xing 。 ren he xian cheng dou ke yi tiao yong gai han shu lai zan ting ling yi ge xian cheng de yun xing ( zhi yao yong you xian cheng de ju bing )。 bu yong shuo , xian cheng ke yi zi xing zan ting yun xing , dan shi bu neng zi xing hui fu yun xing 。SuspendThread fan hui de shi xian cheng de qian yi ge zan ting ji shu 。 xian cheng zan ting de zui duo ci shu ke yi shi MAXIMUM_SUSPEND_COUNT ci 。 zhi de zhu yi de shi ,SuspendThread yu nei gai fang shi de zhi xing shi yi bu jin xing de , dan shi zai xian cheng hui fu yun xing zhi qian , bu hui fa sheng yong hu fang shi de zhi xing 。 zai shi ji huan jing zhong , tiao yong SuspendThread shi bi xu xiao xin , yin wei bu zhi dao zan ting xian cheng yun xing shi ta zai jin xing shen me cao zuo 。 ru guo xian cheng shi tu cong dui zhan zhong fen pei nei cun , na me gai xian cheng jiang zai gai dui zhan shang she zhi yi ge suo 。 dang qi ta xian cheng shi tu fang wen gai dui zhan shi , zhe xie xian cheng de fang wen jiu bei ting zhi , zhi dao di yi ge xian cheng hui fu yun xing 。 zhi you que qie zhi dao mu biao xian cheng shi shen me ( huo zhe mu biao xian cheng zheng zai zuo shen me ), bing qie cai qu qiang you li de cuo shi lai bi mian yin zan ting xian cheng de yun xing er dai lai de wen ti huo si suo zhuang tai ,SuspendThread cai shi an quan de 。
  xian cheng de shui mian
   xian cheng ye neng gao su xi tong , ta bu xiang zai mou ge shi jian duan nei bei tiao du 。 zhe shi tong guo tiao yong Sleep han shu lai shi xian de :
   VOID Sleep(DWORD cMilliseconds)
   gai han shu ke shi xian cheng zan ting zi ji de yun xing , zhi dao cMilliseconds guo qu wei zhi 。 guan yu Sleep han shu , you xia mian ji ge chong yao wen ti zhi de zhu yi :
   • tiao yong Sleep, ke shi xian cheng zi yuan fang qi ta sheng yu de shi jian pian 。
   • xi tong jiang zai da yue de zhi ding hao miao shu nei shi xian cheng bu ke tiao du 。 bu cuo , ru guo gao su xi tong , xiang shui mian 100ms, na me ke yi shui mian da yue zhe me chang shi jian , dan shi ye ke neng shui mian shu miao zhong huo zhe shu fen zhong 。 huan shi na ge fan fu chong shen de gai nian , Windows bu shi ge shi shi cao zuo xi tong 。 sui ran xian cheng ke neng zai gui ding de shi jian bei huan xing , dan shi ta neng fou zuo dao , qu jue yu xi tong
  zhong huan you shen me cao zuo zheng zai jin xing 。
   • ke yi tiao yong Sleep, bing qie wei cMilliseconds) shen shu chuan di INFINITE。 zhe jiang gao su xi tong yong yuan bu yao tiao du gai xian cheng 。 zhe bu shi yi jian zhi de qu zuo de shi qing 。 zui hao shi rang xian cheng tui chu , bing huan yuan ta de dui zhan he nei gai dui xiang 。
   • ke yi jiang 0 chuan di gei Sleep。 zhe jiang gao su xi tong , tiao yong xian cheng jiang shi fang sheng yu de shi jian pian , bing po shi xi tong tiao du ling yi ge xian cheng 。 dan shi , xi tong ke yi dui gang gang tiao yong Sleep de xian cheng chong xin tiao du 。 ru guo bu cun zai duo ge yong you xiang tong you xian ji de ke tiao du xian cheng , jiu hui chu xian zhe zhong qing kuang 。Sleep(0) shi yi ge fei chang you yi si de fang fa 。 yao xiao xin Sleep() shen mi de shi jian tiao zheng wen ti 。Sleep() ke neng hui shi ni de ji qi chu xian te bie de wen ti 。 zhe zhong wen ti zai ling yi tai ji qi shang ke neng wu fa zai xian 。
  qie huan dao ling yi ge xian cheng
   xi tong ti gong le yi ge cheng wei SwitchToThread de han shu , shi de ling yi ge ke tiao du xian cheng ( ru guo cun zai neng gou yun xing )。 dang tiao yong zhe ge han shu de shi hou , xi tong yao cha kan shi fou cun zai yi ge po qie xu yao C P U shi jian de xian cheng 。 ru guo mei you xian cheng po qie xu yao C P U shi jian SwitchToThread jiu hui li ji fan hui 。 ru guo cun zai yi ge po qie xu yao C P U shi jian de xian cheng ,SwitchToThread jiu dui gai xian cheng jin xing tiao du ( gai xian cheng de you xian ji ke neng di yu tiao yong SwitchToThread de xian cheng )。 zhe ge po qie xu yao C P U shi jian de xian cheng ke yi yun xing yi ge shi jian duan , ran hou xi tong tiao du cheng xu zhao chang yun xing 。 gai han shu yuan xu yi ge xu yao zi yuan de xian cheng qiang zhi ling yi ge you xian ji jiao di 、 er mu qian que yong you gai zi yuan de xian cheng fang qi gai zi yuan 。 ru guo tiao yong SwitchToThread han shu shi mei you qi ta xian cheng neng gou yun xing , na me gai han shu fan hui FALSE, fou ze fan hui yi ge fei 0 zhi 。 tiao yong SwitchToThread han shu yu tiao yong Sleep shi xiang si de , cha bie shi SwitchToThread yuan xu you xian ji jiao di de xian cheng yun xing 。 ji shi di you xian ji xian cheng po qie xu yao CPU shi jian , er Sleep ze ke neng yin wei you xian ji guan xi shi de gang fang qi CPU de xian cheng bei li ji chong xin tiao du 。
  you xian ji
   cao zuo xi tong hui fu ze wei mei ge xian cheng fen pei CPU shi jian 。 yi ge xian cheng suo fen pei dao de CPU shi jian zhu yao qu jue yu gai xian cheng de you xian ji , er xian cheng de you xian ji you qu jue yu jin cheng de you xian ji lei he xian cheng ben shen de xiang dui you xian ji 。
  1. jin cheng de you xian ji lei
   jin cheng de you xian ji lei yong lai miao shu yi ge jin cheng de you xian cheng du 。Win32 zhi chi si zhong bu tong de you xian ji lei : Idle、Normal、High he Realtime。 qi zhong ,Normal shi mo ren de you xian ji 。 zai Windows dan yuan zhong , mei yi zhong you xian ji lei dou dui ying zhe yi ge biao zhi 。 dang yao jin xing jin cheng de you xian ji she zhi shi , ke yi yong yi zhong you xian ji lei yu CreateProcess() de shen shu dwCreationFlags jin xing huo cao zuo 。 ling wai , huan ke yi dong tai di wei yi ge yi you de jin cheng tiao zheng you xian ji lei 。 zhe shi hou , tong chang ni yao yong dao xia mian API han shu
  bool SetPriorityClass(HANDLE hProcess,DWORD fdwPriority), qi zhong di yi ge shen shu shi jin cheng de ju bing , ni ke yi tong guo GetCurrentProcess lai huo de dang qian jin cheng de ju bing 。 mei ge you xian ji lei ye dui ying yi ge shu zi , zhi zai 4~ 24 zhi jian 。 zhu yi zai Windows NT/2000 xia , yao you te shu de quan xian cai neng xiu gai jin cheng de you xian lei 。 mo ren de she zhi yuan xu jin cheng she zhi ta men de you xian ji lei , dan shi , zhe xie dou ke yi you xi tong guan li yuan lai guan bi , you qi shi zai gao fu zai de WinNT/2000 fu wu qi shang 。
   da duo shu qing kuang xia , jin cheng de you xian ji lei bu yao bei she wei Realtime。 yin wei , da duo shu cao zuo xi tong ben shen de xian cheng de you xian ji lei bi Realtime di 。 ru guo yi ge jin cheng de dao de C P U shi jian bi cao zuo xi tong ben shen huan duo , hou guo shi wu fa xiang xiang de 。 ji shi jiang jin cheng de you xian ji lei she wei High , ye ke neng yin qi wen ti 。 yin wei , dang gao you xian ji de xian cheng mei you da bu fen kong shi jian huo deng dai wai bu shi jian shi , ta yao cong di you xian ji de xian cheng he jin cheng zhong qiang duo CPU shi jian , zhi dao ta bei yi shi jian zu sai huo chu yu kong xian zhuang tai huo chu li xiao xi 。 suo yi , zai qiang zhan shi duo ren wu cao zuo xi tong zhong ru guo bu neng he li di an pai you xian ji , jiu hen rong yi beng kui 。
  
  
   you xian ji lei
   shuo ming
  
  
   shi shi
   jin cheng zhong de xian cheng bi xu li ji dui shi jian zuo chu xiang ying , yi bian zhi xing guan jian shi jian de ren wu 。
  gai jin cheng zhong de xian cheng huan hui qiang xian yu cao zuo xi tong zu jian zhi qian yun xing 。 shi yong ben you xian ji lei
  shi bi xu ji duan xiao xin
  
  
   gao
   jin cheng zhong de xian cheng bi xu li ji dui shi jian zuo chu xiang ying , yi bian zhi xing guan jian shi jian de ren wu 。
  Task Manager( ren wu guan li qi ) zai zhe ge lei shang yun xing , yi bian yong hu ke yi che xiao tuo
  li kong zhi de jin cheng
  
  
   gao yu zheng chang
   jin cheng zhong de xian cheng zai zheng chang you xian ji yu gao you xian ji zhi jian yun xing ( zhe shi Wi n d o w s
  2 0 0 0 zhong de xin you xian ji lei )
  
  
   zheng chang
   jin cheng zhong de xian cheng mei you te shu de tiao du xu qiu
  
  
   di yu zheng chang
   jin cheng zhong de xian cheng zai zheng chang you xian ji yu kong xian you xian ji zhi jian yun xing ( zhe shi Wi n d o w s
  2 0 0 0 zhong de xin you xian ji lei )
  
  
   kong xian
   jin cheng zhong de xian cheng zai xi tong kong xian shi yun xing 。 gai jin cheng tong chang you ping mu bao hu cheng xu huo hou
  tai shi yong cheng xu he sou ji tong ji shu ju de ruan jian shi yong
  
  
  2. xiang dui you xian ji
   jue ding yi ge xian cheng quan mian de you xian ji de ling yi fang mian shi xiang dui you xian ji 。 you xian ji lei shi zhen dui jin cheng de , ta dui jin cheng nei bu de
  suo you xian cheng dou you xiao 。 er xiang dui you xian ji shi zhen dui mou ge xian cheng de 。 yi ge xian cheng de xiang dui you xian ji ke she wei yi xia qi zhong : Idle、Lowest、Below Normal、Normal、Above Normal、Highest he Time Critical。
  yao she zhi yi ge xian cheng de xiang dui you xian ji , ke yi tong guo API han shu SetThreadPriority lai wan cheng , zai DELPHI zhong , ni ke yi tong guo TThread dui xiang de Priority shu xing lai she zhi 。 huo de xian cheng xiang dui you xian ji de API han shu shi int GetThreadPriority(HANDLE hThread);
  xi tong he ru gen ju you xian ji lai tiao du xian cheng
   mei ge xian cheng dou hui bei fu yu yi ge cong 0( zui di ) dao 31( zui gao ) de you xian ji hao ma 。 dang xi tong que ding jiang na ge xian cheng fen pei gei CPU shi , ta shou xian guan cha you xian ji wei 31 de xian cheng , bing yi xun huan fang shi dui ta men jin xing tiao du 。 ru guo you xian ji wei 31 de xian cheng ke yi tiao du , na me jiu jiang gai xian cheng fu yu yi ge CPU。 zai gai xian cheng de shi jian pian jie shu shi , xi tong yao cha kan shi fou huan you ling yi ge you xian ji wei 31 de xian cheng ke yi yun xing , ru guo you , ta jiang yuan xu gai xian cheng bei fu yu yi ge CPU。 zhi yao you xian ji wei 31 de xian cheng shi ke tiao du de , xi tong jiu jue dui bu hui jiang you xian ji wei 0 dao 30 de xian cheng fen pei gei C P U。 zhe zhong qing kuang cheng wei ke qiu tiao du (starvation)。 dang gao you xian ji xian cheng shi yong da liang de CPU shi jian , cong er shi de di you xian ji xian cheng wu fa yun xing shi , bian hui chu xian ke qiu qing kuang 。 zai duo chu li qi ji suan ji shang chu xian ke qiu qing kuang de ke neng xing yao shao de duo , yin wei zai zhe yang de ji suan ji shang , you xian ji wei 31 he you xian ji wei 30 de xian cheng neng gou tong shi yun xing 。 xi tong zong shi she fa shi CPU bao chi fan mang zhuang tai , zhi you dang mei you xian cheng ke yi tiao du de shi hou , CPU cai chu yu kong xian zhuang tai 。
   ren men ke neng ren wei , zai zhe yang de xi tong zhong , di you xian ji xian cheng yong yuan de bu dao ji hui yun xing 。 bu guo zheng xiang qian mian zhi chu de na yang , zai ren he yi ge shi duan nei , xi tong zhong de da duo shu xian cheng shi bu neng tiao du de 。 li ru , ru guo jin cheng de zhu xian cheng tiao yong GetMessage han shu , er xi tong fa xian mei you xian cheng ke yi gong ta shi yong , na me xi tong jiu zan ting jin cheng de xian cheng yun xing , shi fang gai xian cheng de sheng yu shi jian pian , bing qie li ji jiang CPU fen pei gei ling yi ge deng dai yun xing de xian cheng 。 ru guo mei you wei GetMessage han shu xian shi ke gong jian suo de xiao xi , na me jin cheng de xian cheng jiang bao chi zan ting zhuang tai , bing qie jue bu hui bei fen pei gei CPU。 dan shi , dang xiao xi bei zhi yu xian cheng de dui lie zhong shi , xi tong jiu zhi dao gai xian cheng bu ying gai zai chu yu zan ting zhuang tai 。 ci shi , ru guo mei you geng gao you xian ji de xian cheng xu yao yun xing , xi tong jiu jiang gai xian cheng fen pei gei yi ge CPU。
   gao you xian ji xian cheng jiang qiang zai di you xian ji xian cheng zhi qian yun xing , bu guan di you xian ji xian cheng zheng zai yun xing shen me 。 li ru , ru guo yi ge you xian ji wei 5 de xian cheng zheng zai yun xing , xi tong fa xian yi ge gao you xian ji de xian cheng zhun bei yao yun xing , na me xi tong jiu hui li ji zan ting di you xian ji xian cheng de yun xing ( ji shi ta chu yu ta de shi jian pian zhong ), bing qie jiang C P U fen pei gei gao you xian ji xian cheng , shi ta huo de yi ge wan zheng de shi jian pian 。 huan you , dang xi tong yin dao shi , ta hui chuang jian yi ge te shu de xian cheng , cheng wei 0 ye xian cheng 。 gai xian cheng bei fu yu you xian ji 0, ta shi zheng ge xi tong zhong wei yi de yi ge zai you xian ji 0 shang yun xing de xian cheng 。 dang xi tong zhong mei you ren he xian cheng xu yao zhi xing cao zuo shi ,0 ye xian cheng fu ze jiang xi tong zhong de suo you kong xian R A M ye mian zhi 0。
  dong tai ti gao xian cheng de you xian ji deng ji
   tong guo jiang xian cheng de xiang dui you xian ji yu xian cheng de jin cheng you xian ji lei zong he qi lai kao lv , xi tong jiu ke yi que ding xian cheng de you xian ji deng ji 。 you shi zhe cheng wei xian cheng de ji ben you xian ji deng ji 。
   xi tong chang chang yao ti gao xian cheng de you xian ji deng ji , yi bian dui chuang kou xiao xi huo du qu ci pan deng I/O shi jian zuo chu xiang ying 。
   li ru , zai gao you xian ji lei jin cheng zhong de yi ge zheng chang you xian ji deng ji de xian cheng de ji ben you xian ji deng ji shi 13。 ru guo yong hu an xia yi ge cao zuo jian , xi tong jiu hui jiang yi ge WM_KEYDOWN xiao xi fang ru xian cheng de dui lie zhong 。 you yu yi ge xiao xi yi jing chu xian zai xian cheng de dui lie zhong , yin ci gai xian cheng jiu shi ke tiao du de xian cheng 。 ci wai , jian pan she bei qu dong cheng xu ye neng gou gao su xi tong zan shi ti gao xian cheng de you xian ji deng ji 。 gai xian cheng de you xian ji deng ji ke neng ti gao 2 ji , qi dang qian you xian ji deng ji gai wei 15。 xi tong zai you xian ji wei 15 shi wei yi ge shi jian pian dui gai xian cheng jin xing tiao du 。 yi dan gai shi jian pian jie shu , xi tong bian jiang xian cheng de you xian ji di jian 1, shi xia yi ge shi jian pian de xian cheng you xian ji jiang wei 14。 gai xian cheng de di san ge shi jian pian an you xian ji deng ji 13 lai zhi xing 。 ru guo xian cheng yao qiu zhi xing geng duo de shi jian pian , yun an ta de ji ben you xian ji deng ji 13 lai zhi xing 。 zhu yi , xian cheng de dang qian you xian ji deng ji jue bu hui di yu xian cheng de ji ben you xian ji deng ji 。 ci wai , dao zhi xian cheng cheng wei ke tiao du xian cheng de she bei qu dong cheng xu ke yi jue ding you xian ji deng ji ti gao de shu liang 。Microsoft bing mei you gui ding ge ge she bei qu dong cheng xu ke yi gei xian cheng de you xian ji ti gao duo shao ge deng ji 。 zhe yang jiu shi de Microsoft ke yi bu duan di tiao zheng xian cheng you xian ji ti gao de dong tai deng ji , yi que ding zui jia de zong ti xiang ying xing neng 。 xi tong zhi neng wei ji ben you xian ji deng ji zai 1 zhi 15 zhi jian de xian cheng ti gao qi you xian ji deng ji 。 shi ji shang zhe shi yin wei zhe ge fan wei cheng wei dong tai you xian ji fan wei 。 ci wai , xi tong jue bu hui jiang xian cheng de you xian ji deng ji ti gao dao shi shi fan wei ( gao yu 15)。 you yu shi shi fan wei zhong de xian cheng neng gou zhi xing da duo shu cao zuo xi tong de han shu , yin ci gei deng ji de ti gao gui ding yi ge fan wei , jiu ke yi fang zhi ying yong cheng xu gan rao cao zuo xi tong de yun xing 。 ling wai , xi tong jue bu hui dong tai ti gao shi shi fan wei nei de xian cheng you xian ji deng ji 。
   ling yi zhong qing kuang ye hui dao zhi xi tong dong tai di ti gao xian cheng de you xian ji deng ji 。 bi ru you yi ge you xian ji wei 4 de xian cheng zhun bei yun xing dan shi que bu neng yun xing , yin wei yi ge you xian ji wei 8 de xian cheng zheng lian xu bei tiao du 。 zai zhe zhong qing kuang xia , you xian ji wei 4 de xian cheng jiu fei chang ke wang de dao CPU shi jian 。 dang xi tong fa xian yi ge xian cheng zai da yue 3 zhi 4s nei yi zhi ke wang de dao C P U shi jian , ta jiu jiang zhe ge ke wang de dao CPU shi jian de xian cheng de you xian ji dong tai ti gao dao 15, bing rang gai xian cheng yun xing liang bei yu ta de shi jian liang 。 dang dao le liang bei shi jian liang de shi hou , gai xian cheng de you xian ji li ji fan hui dao ta de ji ben you xian ji 。
   xi tong dong tai de gai bian you xian ji , zai wo men bian cheng de shi hou hui chan sheng bu liang ying xiang , wei ci , huan you liang ge API han shu ke yi shi de xi tong de ci gong neng bu qi zuo yong 。
  bool SetProcessPriorityBoost(HANDLE hProcess,bool disablePriorityboost);
  bool SetThreadPriorityBoost(HANDLE hThread,bool disablePriorityboost);
  cong ming zi ni jiu ying gai ke yi kan chu , di yi ge API han shu ke yi ji huo huo ting yong zhi ding jin cheng suo you xian cheng de you xian ji ti gao gong neng , er hou mian yi ge ze shi zhen dui te ding xian cheng de 。
  li zi : guan jian de dai ma ru xia
WIN32下DELPHI中的多线程【线程的调度】(二)
WIN32下DELPHI中的多线程【线程的调度】(二)
...{
WIN32下DELPHI中的多线程【线程的调度】(二)
zuo zhe :wudi_1982
WIN32下DELPHI中的多线程【线程的调度】(二)
lian xi fang shi :wudi_1982@hotmail.com
WIN32下DELPHI中的多线程【线程的调度】(二)
zhuan zai qing zhu ming chu chu
WIN32下DELPHI中的多线程【线程的调度】(二)
ben dai ma zhi zai yan shi xian cheng de tiao du , hen duo wei zhi mei you jia ru shi dang de kong zhi he zi yuan shi fang , qing an zhao hou xu cao zuo zhi xing
WIN32下DELPHI中的多线程【线程的调度】(二)
}
WIN32下DELPHI中的多线程【线程的调度】(二)
type
WIN32下DELPHI中的多线程【线程的调度】(二)
TSleepType=(stSleep,stSwitch);
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
// yan shi xian cheng tiao du de TThread pai sheng lei
WIN32下DELPHI中的多线程【线程的调度】(二)
TPriThread1=class(TThread)
WIN32下DELPHI中的多线程【线程的调度】(二)
private
WIN32下DELPHI中的多线程【线程的调度】(二)
CurCount : integer; // dang qian ji shu
WIN32下DELPHI中的多线程【线程的调度】(二)
Flb : TLabel; // yong lai xian shi dang qian ji shu de label
WIN32下DELPHI中的多线程【线程的调度】(二)
FCanSleep : Boolean; // shi fou zi dong shi fang shi jian pian
WIN32下DELPHI中的多线程【线程的调度】(二)
FSleepMs : integer;
WIN32下DELPHI中的多线程【线程的调度】(二)
FSleepType : TSleepType;// shi fang shi jian pian de fang shi
WIN32下DELPHI中的多线程【线程的调度】(二)
procedure GetRestult;
WIN32下DELPHI中的多线程【线程的调度】(二)
protected
WIN32下DELPHI中的多线程【线程的调度】(二)
procedure Execute;override;
WIN32下DELPHI中的多线程【线程的调度】(二)
public
WIN32下DELPHI中的多线程【线程的调度】(二)
constructor Create(CreateSuspended: Boolean;ALabel : TLabel);
WIN32下DELPHI中的多线程【线程的调度】(二)
property CanSleep : boolean read FCanSleep write FCanSleep;
WIN32下DELPHI中的多线程【线程的调度】(二)
property SleepMs : integer read FSleepMs write FSleepMs;
WIN32下DELPHI中的多线程【线程的调度】(二)
property SleepType : TSleepType read FSleepType write FSleepType;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
....
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
WIN32下DELPHI中的多线程【线程的调度】(二)
...{ TPriThread1 de shi xian }
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
constructor TPriThread1.Create(CreateSuspended: Boolean; ALabel: TLabel);
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
// gou zao han shu
WIN32下DELPHI中的多线程【线程的调度】(二)
flb := ALabel;
WIN32下DELPHI中的多线程【线程的调度】(二)
FSleepMs := 0;
WIN32下DELPHI中的多线程【线程的调度】(二)
FCanSleep := true;
WIN32下DELPHI中的多线程【线程的调度】(二)
FSleepType := stSleep;
WIN32下DELPHI中的多线程【线程的调度】(二)
inherited create(CreateSuspended);
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
procedure TPriThread1.Execute;
WIN32下DELPHI中的多线程【线程的调度】(二)
var
WIN32下DELPHI中的多线程【线程的调度】(二)
i : integer;
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
inherited;
WIN32下DELPHI中的多线程【线程的调度】(二)
FreeOnTerminate := true;
WIN32下DELPHI中的多线程【线程的调度】(二)
CurCount := 0;
WIN32下DELPHI中的多线程【线程的调度】(二)
for i := 0 to 100000 do
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
CurCount := i;// gai bian dang qian ji shu
WIN32下DELPHI中的多线程【线程的调度】(二)
Synchronize(GetRestult);// xian shi jie guo
WIN32下DELPHI中的多线程【线程的调度】(二)
if FCanSleep then// shi fou zi dong shi fang shi jian pian
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
// gen ju shi fang shi jian pian de bu tong fang shi jin xing xiang ying cao zuo
WIN32下DELPHI中的多线程【线程的调度】(二)
case FSleepType of
WIN32下DELPHI中的多线程【线程的调度】(二)
stSleep : Sleep(SleepMs);// shui mian
WIN32下DELPHI中的多线程【线程的调度】(二)
stSwitch : SwitchToThread;// tiao yong qi ta xian cheng
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
procedure TPriThread1.GetRestult;
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
flb.Caption := IntToStr(CurCount);
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
WIN32下DELPHI中的多线程【线程的调度】(二)
...{Form1 de zhu yao dai ma }
WIN32下DELPHI中的多线程【线程的调度】(二)
procedure TForm1.btnPThread1CreateClick(Sender: TObject);
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
// sheng cheng liang ge xian cheng
WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread1 := TPriThread1.Create( not ckbx1State.Checked,lab1);
WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread2 := TPriThread1.Create(not ckbx2State.Checked,lab2);
WIN32下DELPHI中的多线程【线程的调度】(二)
// de dao ta men dang qian de you xian ji
WIN32下DELPHI中的多线程【线程的调度】(二)
lb1p.Caption := inttostr(GetThreadPriority(MyPThread1.Handle));
WIN32下DELPHI中的多线程【线程的调度】(二)
lb2p.Caption := inttostr(GetThreadPriority(MyPThread2.Handle));
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
procedure TForm1.btnPThread1ResClick(Sender: TObject);
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
// zhi xing xian cheng
WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread1.Resume;
WIN32下DELPHI中的多线程【线程的调度】(二)
ckbx1State.Checked := true;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread2.Resume;
WIN32下DELPHI中的多线程【线程的调度】(二)
ckbx2State.Checked := true;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
procedure TForm1.btnPThread1SudClick(Sender: TObject);
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
// gua qi xian cheng
WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread1.Suspend;
WIN32下DELPHI中的多线程【线程的调度】(二)
ckbx1State.Checked := false;
WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread2.Suspend;
WIN32下DELPHI中的多线程【线程的调度】(二)
ckbx2State.Checked := false;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
procedure TForm1.btnUpPThread1Click(Sender: TObject);
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
// zai xian cheng gua qi shi , ti gao di yi ge xian cheng de xiang dui you xian ji
WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread1.Priority := tpHigher;
WIN32下DELPHI中的多线程【线程的调度】(二)
// xian shi dang qian de you xian ji dao ping mu
WIN32下DELPHI中的多线程【线程的调度】(二)
lb1p.Caption := inttostr(GetThreadPriority(MyPThread1.Handle));
WIN32下DELPHI中的多线程【线程的调度】(二)
// MyPThread2.Priority := tpHigher;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
procedure TForm1.btnUpdateSleepClick(Sender: TObject);
WIN32下DELPHI中的多线程【线程的调度】(二)
begin
WIN32下DELPHI中的多线程【线程的调度】(二)
// xiu gai liang ge xian cheng de shi jian pian shi fang fang shi
WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread1.CanSleep := ckbxAllowSleep1.Checked;
WIN32下DELPHI中的多线程【线程的调度】(二)
case RadioGroup1.ItemIndex of
WIN32下DELPHI中的多线程【线程的调度】(二)
0 : MyPThread1.SleepType := stSleep;
WIN32下DELPHI中的多线程【线程的调度】(二)
1 : MyPThread1.SleepType := stSwitch;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
MyPThread2.CanSleep := ckbxAllowSleep2.Checked;
WIN32下DELPHI中的多线程【线程的调度】(二)
case RadioGroup2.ItemIndex of
WIN32下DELPHI中的多线程【线程的调度】(二)
0 : MyPThread2.SleepType := stSleep;
WIN32下DELPHI中的多线程【线程的调度】(二)
1 : MyPThread2.SleepType := stSwitch;
WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)
end;
WIN32下DELPHI中的多线程【线程的调度】(二)

WIN32下DELPHI中的多线程【线程的调度】(二)

  chuang ti xiao guo :
WIN32下DELPHI中的多线程【线程的调度】(二)

  rang wo men lai yong zhe ge cheng xu ce shi yi xie xiao guo :
  1、 ji ben zhi xing 。 cheng xu yun xing zhi hou , shi yong mo ren she zhi , dian ji 【 chuang jian xian cheng 】 an niu , xian cheng jiang bei chuang jian , bing qie gua qi , zhe shi ni ke yi jian ge de dian ji 【 zhi xing xian cheng 】 he 【 gua qi xian cheng 】 an niu , ni hui zai ping mu shang kan dao xian cheng de dang qian ji shu , zhu yi zhe liang ge ji shu zhi jian de cha zhi , yi ji zheng ge jie mian de zhi xing xiao guo ( wo zhi de shi zai ni rang xian cheng bu duan de zhi xing he gua qi zhi jian jie mian shi fou hui chu xian bu shua xin de qing kuang ), dang xian cheng zhi xing wan bi zhi hou , guan bi cheng xu 。
  2、 tong guo Sleep(0) shi fang shi jian pian yan shi xian cheng tiao du 。 yun xing cheng xu , shi yong mo ren she zhi , dian ji 【 chuang jian xian cheng 】 an niu , ran hou jiang liang ge xian cheng de zi shi fang shi jian pian gong neng tong tong qu diao ( ye jiu shi qu diao ckbxAllowSleep1 and 2 de gou gou ), ran hou dian ji 【 xiu gai shui mian fang shi 】 an niu , sui hou ni ke yi jin xing jian ge dian ji 【 zhi xing xian cheng 】 he 【 gua qi xian cheng 】 an niu , duo zuo ji ci zhe yang de cao zuo , guan cha liang ge ji shu zhi jian de cha zhi , he ce shi 1 de cha zhi bi jiao yi xia 。 wo xiang ni ying gai neng xiang dao xie shen me 。 ran hou , ji hu ke yi ken ding ni de jie mian jiang hui chu xian wu fa shua xin de qing kuang , bing qie ni de shu biao wu fa li ji zai ci jie mian shang jin xing qi ta de cao zuo 。 zhe ge shi hou , shao deng yi xia , ni hui fa xian guo le yi hui er , liang ge dang qian ji shu dou bei shua xin le 。 wei shen me ?? zhe shi , wo men chu le kao lv wo men chuang jian de liang ge xian cheng zhi wai , ni huan yao kao lv de ni cheng xu ben shen de zhu xian cheng yi ji qi ta ke neng cun zai de fu shu xian cheng , wo men zai qu cheng xu zhong xian cheng de na duan xun huan dai ma ,
   CurCount := i;// gai bian dang qian ji shu
   Synchronize(GetRestult);// xian shi jie guo
   if FCanSleep then// shi fou zi dong shi fang shi jian pian
   begin
   // gen ju shi fang shi jian pian de bu tong fang shi jin xing xiang ying cao zuo
   case FSleepType of
   stSleep : Sleep(SleepMs);// shui mian
   stSwitch : SwitchToThread;// tiao yong qi ta xian cheng
   end;
   end;
   ni ying gai kan dao xian cheng jiang dang qian ji shu xian shi zai ping mu shang de cao zuo shi zhi xing le Synchronize(GetRestult), zhe li , yin wei wo men de xian cheng he VCL jie mian fa sheng le jiao hu , wo men bi xu dui Synchronize you suo le jie , qu kan VCL de yuan ma , ni hui fa xian , dang ni zai cheng xu zhong di yi ci chuang jian yi ge fu shu xian cheng shi , VCL jiang hui cong zhu xian cheng huan jing zhong chuang jian he wei hu yi ge yin han de xian cheng chuang kou 。 ci chuang kou wei yi de mu de shi ba tong guo Synchronize() tiao yong de fang fa pai dui 。Synchronize() ba you Method shen shu chuan di guo lai de fang fa bao cun zai TThread de FMethod zi duan zhong , ran hou , gei xian cheng chuang kou fa yi ge CM_EXECPROC xiao xi , bing qie ba xiao xi de lParam shen shu she wei self( zhe li zhi xian cheng dui xiang )。 dang xian cheng chuang kou de chuang kou guo cheng shou dao zhe ge xiao xi hou , ta jiu tiao yong FMethod zi duan suo zhi ding de fang fa 。 you yu xian cheng chuang kou shi zai zhu xian cheng nei chuang jian de , xian cheng chuang kou de chuang kou guo cheng ye jiang bei zhu xian cheng zhi xing 。 yin ci ,FMethod zi duan suo zhi ding de fang fa jiu zai zhu xian cheng nei zhi xing 。
   zai wo men xuan ze shi fang shi jian pian de mo shi xia , zai zhe li , wu lun wo men shi yong Sleep huan shi SwitchToThread, dang qian xian cheng dou hui li ji shi fang shi jian pian , yin wei zhe shi wo men bing mei you xiu gai xian cheng de you xian ji , ta men dou zai tong yang de you xian ji huan jing xia yun xing , na me dang zhan yong CPU de xian cheng shi fang shi jian pian hou , qi ta xian cheng jiang ke yi xiang dui qing song de de dao CPU, suo yi zai shi yong shi fang shi jian pian de mo shi xia , jie mian de shua xin hui liang hao 。 bing qie tiao du xiang dui you xu 。
  3、Sleep he SwitchToThread qu bie de yan shi 。 yun xing cheng xu , shi yong mo ren she zhi , dian ji 【 chuang jian xian cheng 】 an niu , ran hou dian ji 【 ti gao xian cheng 1 de you xian ji 】 an niu , zai dian ji 【 zhi xing xian cheng 】 zhe shi , liang ge xian cheng jiang bu zai shi tong yang de you xian ji , qi ta she zhi yi ran shi mo ren de ( shi yong sleep fang shi shi fang shi jian pian ), ni hui kan dao xian cheng 1 shou xian zhi xing , xian cheng 2 chu yu ke tiao du mo shi , dan bing mei you bei tiao du ( dang qian ji shu mei you shua xin ), bing qie ping mu ye bu shua xin , zai shao deng yi duan shi jian zhi hou , ping mu shua xin , xian cheng 2 ye kai shi yun xing , bing qie ci shi ping mu shua xin zheng chang 。 wei shen me ne ? hui tou qu kan ben wen shang mian de nei rong , dang xian cheng 1 de you xian ji ti gao zhi hou , xi tong hui shou xian tiao du ta , sui ran ta shi yong sleep(0) lai shi fang shi jian pian , dan dang shi jian pian shi fang hou , yin wei ta de you xian ji xiang dui jiao gao , xi tong yi ran hui tiao du xian cheng 1, suo yi ci shi , xian cheng 2 jiang bu neng zhi xing , jie mian ye bu neng you xiao shua xin 。 zai zhe ge si lu xia , zai zuo yi ge ce shi , shi yong tong yang de fang shi , zhi bu guo zhe ci , zai xian cheng zhi xing zhi qian , chu le ti gao xian cheng 1 de you xian ji zhi wai , huan jiang xian cheng 1 shi fang shi jian pian fang shi gai wei SwitchToThread, ci shi ni jiu ke yi kan dao liang ge xian cheng dou you ji hui zhi xing , bing qie jie mian ye jiang you xiao shua xin 。
  4、 ni huan ke yi zuo qi ta pei zhi xin xi de ce shi , xiang xin hui jia shen dui WIN32 ping tai xia xian cheng tiao du de le jie 。
  shen kao wen xian
  1、《DELPHI5 kai fa ren yuan zhi nan 》
  2、《WINDOWS gai xin bian cheng 》
  zhu : yi shang cheng xu zai D7+WINXP xia ce shi tong guo
  zhuan zai qing zhu ming chu chu 。【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
xian cheng de tiao du mei ge xian cheng shi yong you yi ge shang xia wen jie gou de , zhe ge jie gou wei hu zai xian cheng de nei gai dui xiang zhong 。 zhe ge shang xia wen jie gou fan yang le xian cheng shang ci yun xing shi gai xian cheng de C P U ji cun qi de zhuang tai 。 mei ge 20ms zuo you ,Windows yao cha kan dang qian cun zai de suo you xian cheng nei gai dui xiang 。 zai zhe xie dui xiang zhong , zhi you mou xie dui xiang bei shi wei ke yi tiao du de dui xiang 。Windows xuan ze ke tiao du de xian cheng nei gai dui xiang zhong de yi ge , jiang ta jia zai dao C P U de ji cun qi zhong , ta de zhi shi shang ci bao cun zai xian cheng de huan jing zhong de zhi 。 zhe xiang cao zuo cheng wei shang xia wen zhuan huan 。Windows shi ji shang bao cun le yi ge ji lu , ta shuo ming mei ge xian cheng huo de le duo shao ge yun xing ji hui 。 Windows bei cheng wei qiang zhan shi duo xian cheng cao zuo xi tong , yin wei yi ge xian cheng ke yi sui shi ting zhi yun xing , sui hou ling yi ge xian cheng ke jin xing tiao du 。 ru ni suo jian , ke yi dui ta jin xing yi ding cheng du de kong zhi , dan shi bu neng tai duo 。 zhu yi , wu fa bao zheng xian cheng zong shi neng gou yun xing , ye bu neng bao zheng xian cheng neng gou de dao zheng ge jin cheng , wu fa bao zheng qi ta xian cheng bu bei yuan xu yun xing deng deng 。 wo zai bian xie chuan kou tong xun cheng xu de shi hou , qi chu , wo you yi ge tian zhen de xiang fa ,“ zai win32 ping tai xia , ru he neng gou bao zheng cong chuan kou chuan song guo lai de shu ju , zai shu ju dao da hou 1MS nei kai shi yun xing ?”。 wei ci , wo zeng jing zuo le xu duo shi yan , dan dang wo zhen zheng le jie le yi xie win32 ping tai de zhi shi , wo de dao le da an , ban bu dao 。 zhi you shi shi cao zuo xi tong cai neng zuo chu zhe yang de cheng nuo , dan Windows bu shi shi shi cao zuo xi tong 。 shi shi cao zuo xi tong bi xu qing chu di zhi dao ta shi zai shen me ying jian shang yun xing , zhe yang ta cai neng zhi dao ta de ying pan kong zhi qi he jian pan deng de deng dai shi jian 。Microsoft dui Windows gui ding de mu biao shi , shi ta neng gou zai ge zhong bu tong de ying jian shang yun xing , ji neng gou zai bu tong de CPU、 bu tong de qu dong qi he bu tong de wang luo shang yun xing 。 jian er yan zhi ,Windows mei you she ji cheng wei yi zhong shi shi cao zuo xi tong 。 Windows xi tong zhi tiao du ke yi tiao du de xian cheng 。 na me shen me shi ke yi tiao du de xian cheng , shen me shi bu ke yi tiao du de xian cheng ne ? li ru , you xie xian cheng dui xiang de zan ting ji shu da yu 1( ji lu zai xian cheng nei gai dui xiang de shang xia wen jie gou zhong )。 zhe yi wei zhe gai xian cheng yi jing zan ting yun xing , bu ying gai gei ta an pai ren he C P U shi jian 。 huan ji de shang wen zhong zeng jing ti dao de CREATE_SUSPENDED biao zhi ma ? zai chuang jian yi ge xian cheng de shi hou ,createThread han shu jie shou de dao shu di er ge shen shu zhong fu zhi CREATE_SUSPENDED jiu ke yi chuang jian yi ge zan ting de xian cheng 。 chu le zan ting de xian cheng wai , qi ta xu duo xian cheng ye shi bu ke tiao du de xian cheng , yin wei ta men zheng zai deng dai mou xie shi qing de fa sheng 。 li ru , ru guo ji shi ben cheng xu , ru guo ni bu jian ru ren he shu ju , na me ta de xian cheng jiu mei you shen me shi qing yao zuo 。 xi tong bu gei wu shi ke zuo de xian cheng fen pei CPU shi jian 。 dang yi dong ta de chuang kou shi , huo zhe ta de chuang kou xu yao shua xin ta de nei rong , huo zhe jiang shu ju jian ru ji shi ben , xi tong jiu hui zi dong shi ta de xian cheng cheng wei ke tiao du de xian cheng 。 dan qie ji , zhe bing bu yi wei zhe ta de xian cheng li ji huo de le CPU shi jian 。 ta zhi shi biao shi ji shi ben de de xian cheng you shi qing ke zuo , xi tong jiang she fa zai mou ge shi jian ( bu jiu de jiang lai ) dui ta jin xing tiao du 。 xian cheng de zan ting he zhi xing wo men qian mian shuo guo , zai xian cheng nei gai dui xiang de nei bu you yi ge zhi , yong yu zhi ming xian cheng de zan ting ji shu 。 dang tiao yong CreateThread han shu shi , jiu chuang jian le xian cheng de nei gai dui xiang , bing qie ta de zan ting ji shu bei chu shi hua wei 1。 zhe ke yi fang zhi xian cheng bei tiao du dao CPU zhong 。 dang ran , zhe shi hen you yong de , yin wei xian cheng de chu shi hua xu yao shi jian , ni bu xi wang zai xi tong zuo hao chong fen de zhun bei zhi qian jiu kai shi zhi xing xian cheng 。 dang xian cheng wan quan chu shi hua hao le zhi hou , yao cha kan shi fou yi jing chuan di le CREATE_SUSPENDED biao zhi 。 ru guo yi jing chuan di le zhe ge biao zhi , na me zhe xie han shu jiu fan hui , tong shi xin xian cheng chu yu zan ting zhuang tai 。 ru guo shang wei chuan di gai biao zhi , na me gai han shu jiang xian cheng de zan ting ji shu di jian wei 0。 dang xian cheng de zan ting ji shu shi 0 de shi hou , chu fei xian cheng zheng zai deng dai qi ta mou zhong shi qing de fa sheng , fou ze gai xian cheng jiu chu yu ke tiao du zhuang tai 。 zai zan ting zhuang tai zhong chuang jian yi ge xian cheng , jiu neng gou zai xian cheng you ji hui zhi xing ren he dai ma zhi qian gai bian xian cheng de yun xing huan jing ( ru you xian ji )。 yi dan gai bian le xian cheng de huan jing , bi xu shi xian cheng cheng wei ke tiao du xian cheng 。 yao jin xing zhe xiang cao zuo , ke yi tiao yong ResumeThread, jiang xian cheng ju bing chuan di gei ta , ru guo ResumeThread, han shu yun xing cheng gong , ta jiang fan hui xian cheng de qian yi ge zan ting ji shu , fou ze fan hui 0xFFFFFFFF。 zhu yi zhe li , ta fan hui de shi qian yi ge zan ting ji shu 。 dan ge xian cheng ke yi zan ting ruo gan ci 。 ru guo yi ge xian cheng zan ting le 3 ci , ta bi xu hui fu 3 ci , ran hou ta cai ke yi bei fen pei gei yi ge C P U。 dang chuang jian xian cheng shi , chu le shi yong CREATE_SUSPENDED wai , ye ke yi tiao yong SuspendThread han shu lai zan ting xian cheng de yun xing 。 ren he xian cheng dou ke yi tiao yong gai han shu lai zan ting ling yi ge xian cheng de yun xing ( zhi yao yong you xian cheng de ju bing )。 bu yong shuo , xian cheng ke yi zi xing zan ting yun xing , dan shi bu neng zi xing hui fu yun xing 。SuspendThread fan hui de shi xian cheng de qian yi ge zan ting ji shu 。 xian cheng zan ting de zui duo ci shu ke yi shi MAXIMUM_SUSPEND_COUNT ci 。 zhi de zhu yi de shi ,SuspendThread yu nei gai fang shi de zhi xing shi yi bu jin xing de , dan shi zai xian cheng hui fu yun xing zhi qian , bu hui fa sheng yong hu fang shi de zhi xing 。 zai shi ji huan jing zhong , tiao yong SuspendThread shi bi xu xiao xin , yin wei bu zhi dao zan ting xian cheng yun xing shi ta zai jin xing shen me cao zuo 。 ru guo xian cheng shi tu cong dui zhan zhong fen pei nei cun , na me gai xian cheng jiang zai gai dui zhan shang she zhi yi ge suo 。 dang qi ta xian cheng shi tu fang wen gai dui zhan shi , zhe xie xian cheng de fang wen jiu bei ting zhi , zhi dao di yi ge xian cheng hui fu yun xing 。 zhi you que qie zhi dao mu biao xian cheng shi shen me ( huo zhe mu biao xian cheng zheng zai zuo shen me ), bing qie cai qu qiang you li de cuo shi lai bi mian yin zan ting xian cheng de yun xing er dai lai de wen ti huo si suo zhuang tai ,SuspendThread cai shi an quan de 。 xian cheng de shui mian xian cheng ye neng gao su xi tong , ta bu xiang zai mou ge shi jian duan nei bei tiao du 。 zhe shi tong guo tiao yong Sleep han shu lai shi xian de : VOID Sleep(DWORD cMilliseconds) gai han shu ke shi xian cheng zan ting zi ji de yun xing , zhi dao cMilliseconds guo qu wei zhi 。 guan yu Sleep han shu , you xia mian ji ge chong yao wen ti zhi de zhu yi : • tiao yong Sleep, ke shi xian cheng zi yuan fang qi ta sheng yu de shi jian pian 。 • xi tong jiang zai da yue de zhi ding hao miao shu nei shi xian cheng bu ke tiao du 。 bu cuo , ru guo gao su xi tong , xiang shui mian 100ms, na me ke yi shui mian da yue zhe me chang shi jian , dan shi ye ke neng shui mian shu miao zhong huo zhe shu fen zhong 。 huan shi na ge fan fu chong shen de gai nian , Windows bu shi ge shi shi cao zuo xi tong 。 sui ran xian cheng ke neng zai gui ding de shi jian bei huan xing , dan shi ta neng fou zuo dao , qu jue yu xi tong zhong huan you shen me cao zuo zheng zai jin xing 。 • ke yi tiao yong Sleep, bing qie wei cMilliseconds) shen shu chuan di INFINITE。 zhe jiang gao su xi tong yong yuan bu yao tiao du gai xian cheng 。 zhe bu shi yi jian zhi de qu zuo de shi qing 。 zui hao shi rang xian cheng tui chu , bing huan yuan ta de dui zhan he nei gai dui xiang 。 • ke yi jiang 0 chuan di gei Sleep。 zhe jiang gao su xi tong , tiao yong xian cheng jiang shi fang sheng yu de shi jian pian , bing po shi xi tong tiao du ling yi ge xian cheng 。 dan shi , xi tong ke yi dui gang gang tiao yong Sleep de xian cheng chong xin tiao du 。 ru guo bu cun zai duo ge yong you xiang tong you xian ji de ke tiao du xian cheng , jiu hui chu xian zhe zhong qing kuang 。Sleep(0) shi yi ge fei chang you yi si de fang fa 。 yao xiao xin Sleep() shen mi de shi jian tiao zheng wen ti 。Sleep() ke neng hui shi ni de ji qi chu xian te bie de wen ti 。 zhe zhong wen ti zai ling yi tai ji qi shang ke neng wu fa zai xian 。 qie huan dao ling yi ge xian cheng xi tong ti gong le yi ge cheng wei SwitchToThread de han shu , shi de ling yi ge ke tiao du xian cheng ( ru guo cun zai neng gou yun xing )。 dang tiao yong zhe ge han shu de shi hou , xi tong yao cha kan shi fou cun zai yi ge po qie xu yao C P U shi jian de xian cheng 。 ru guo mei you xian cheng po qie xu yao C P U shi jian SwitchToThread jiu hui li ji fan hui 。 ru guo cun zai yi ge po qie xu yao C P U shi jian de xian cheng ,SwitchToThread jiu dui gai xian cheng jin xing tiao du ( gai xian cheng de you xian ji ke neng di yu tiao yong SwitchToThread de xian cheng )。 zhe ge po qie xu yao C P U shi jian de xian cheng ke yi yun xing yi ge shi jian duan , ran hou xi tong tiao du cheng xu zhao chang yun xing 。 gai han shu yuan xu yi ge xu yao zi yuan de xian cheng qiang zhi ling yi ge you xian ji jiao di 、 er mu qian que yong you gai zi yuan de xian cheng fang qi gai zi yuan 。 ru guo tiao yong SwitchToThread han shu shi mei you qi ta xian cheng neng gou yun xing , na me gai han shu fan hui FALSE, fou ze fan hui yi ge fei 0 zhi 。 tiao yong SwitchToThread han shu yu tiao yong Sleep shi xiang si de , cha bie shi SwitchToThread yuan xu you xian ji jiao di de xian cheng yun xing 。 ji shi di you xian ji xian cheng po qie xu yao CPU shi jian , er Sleep ze ke neng yin wei you xian ji guan xi shi de gang fang qi CPU de xian cheng bei li ji chong xin tiao du 。 you xian ji cao zuo xi tong hui fu ze wei mei ge xian cheng fen pei CPU shi jian 。 yi ge xian cheng suo fen pei dao de CPU shi jian zhu yao qu jue yu gai xian cheng de you xian ji , er xian cheng de you xian ji you qu jue yu jin cheng de you xian ji lei he xian cheng ben shen de xiang dui you xian ji 。 1. jin cheng de you xian ji lei jin cheng de you xian ji lei yong lai miao shu yi ge jin cheng de you xian cheng du 。Win32 zhi chi si zhong bu tong de you xian ji lei : Idle、Normal、High he Realtime。 qi zhong ,Normal shi mo ren de you xian ji 。 zai Windows dan yuan zhong , mei yi zhong you xian ji lei dou dui ying zhe yi ge biao zhi 。 dang yao jin xing jin cheng de you xian ji she zhi shi , ke yi yong yi zhong you xian ji lei yu CreateProcess() de shen shu dwCreationFlags jin xing huo cao zuo 。 ling wai , huan ke yi dong tai di wei yi ge yi you de jin cheng tiao zheng you xian ji lei 。 zhe shi hou , tong chang ni yao yong dao xia mian API han shu bool SetPriorityClass(HANDLE hProcess,DWORD fdwPriority), qi zhong di yi ge shen shu shi jin cheng de ju bing , ni ke yi tong guo GetCurrentProcess lai huo de dang qian jin cheng de ju bing 。 mei ge you xian ji lei ye dui ying yi ge shu zi , zhi zai 4~ 24 zhi jian 。 zhu yi zai Windows NT/2000 xia , yao you te shu de quan xian cai neng xiu gai jin cheng de you xian lei 。 mo ren de she zhi yuan xu jin cheng she zhi ta men de you xian ji lei , dan shi , zhe xie dou ke yi you xi tong guan li yuan lai guan bi , you qi shi zai gao fu zai de WinNT/2000 fu wu qi shang 。 da duo shu qing kuang xia , jin cheng de you xian ji lei bu yao bei she wei Realtime。 yin wei , da duo shu cao zuo xi tong ben shen de xian cheng de you xian ji lei bi Realtime di 。 ru guo yi ge jin cheng de dao de C P U shi jian bi cao zuo xi tong ben shen huan duo , hou guo shi wu fa xiang xiang de 。 ji shi jiang jin cheng de you xian ji lei she wei High , ye ke neng yin qi wen ti 。 yin wei , dang gao you xian ji de xian cheng mei you da bu fen kong shi jian huo deng dai wai bu shi jian shi , ta yao cong di you xian ji de xian cheng he jin cheng zhong qiang duo CPU shi jian , zhi dao ta bei yi shi jian zu sai huo chu yu kong xian zhuang tai huo chu li xiao xi 。 suo yi , zai qiang zhan shi duo ren wu cao zuo xi tong zhong ru guo bu neng he li di an pai you xian ji , jiu hen rong yi beng kui 。 you xian ji lei shuo ming shi shi jin cheng zhong de xian cheng bi xu li ji dui shi jian zuo chu xiang ying , yi bian zhi xing guan jian shi jian de ren wu 。 gai jin cheng zhong de xian cheng huan hui qiang xian yu cao zuo xi tong zu jian zhi qian yun xing 。 shi yong ben you xian ji lei shi bi xu ji duan xiao xin gao jin cheng zhong de xian cheng bi xu li ji dui shi jian zuo chu xiang ying , yi bian zhi xing guan jian shi jian de ren wu 。 Task Manager( ren wu guan li qi ) zai zhe ge lei shang yun xing , yi bian yong hu ke yi che xiao tuo li kong zhi de jin cheng gao yu zheng chang jin cheng zhong de xian cheng zai zheng chang you xian ji yu gao you xian ji zhi jian yun xing ( zhe shi Wi n d o w s 2 0 0 0 zhong de xin you xian ji lei ) zheng chang jin cheng zhong de xian cheng mei you te shu de tiao du xu qiu di yu zheng chang jin cheng zhong de xian cheng zai zheng chang you xian ji yu kong xian you xian ji zhi jian yun xing ( zhe shi Wi n d o w s 2 0 0 0 zhong de xin you xian ji lei ) kong xian jin cheng zhong de xian cheng zai xi tong kong xian shi yun xing 。 gai jin cheng tong chang you ping mu bao hu cheng xu huo hou tai shi yong cheng xu he sou ji tong ji shu ju de ruan jian shi yong 2. xiang dui you xian ji jue ding yi ge xian cheng quan mian de you xian ji de ling yi fang mian shi xiang dui you xian ji 。 you xian ji lei shi zhen dui jin cheng de , ta dui jin cheng nei bu de suo you xian cheng dou you xiao 。 er xiang dui you xian ji shi zhen dui mou ge xian cheng de 。 yi ge xian cheng de xiang dui you xian ji ke she wei yi xia qi zhong : Idle、Lowest、Below Normal、Normal、Above Normal、Highest he Time Critical。 yao she zhi yi ge xian cheng de xiang dui you xian ji , ke yi tong guo API han shu SetThreadPriority lai wan cheng , zai DELPHI zhong , ni ke yi tong guo TThread dui xiang de Priority shu xing lai she zhi 。 huo de xian cheng xiang dui you xian ji de API han shu shi int GetThreadPriority(HANDLE hThread); xi tong he ru gen ju you xian ji lai tiao du xian cheng mei ge xian cheng dou hui bei fu yu yi ge cong 0( zui di ) dao 31( zui gao ) de you xian ji hao ma 。 dang xi tong que ding jiang na ge xian cheng fen pei gei CPU shi , ta shou xian guan cha you xian ji wei 31 de xian cheng , bing yi xun huan fang shi dui ta men jin xing tiao du 。 ru guo you xian ji wei 31 de xian cheng ke yi tiao du , na me jiu jiang gai xian cheng fu yu yi ge CPU。 zai gai xian cheng de shi jian pian jie shu shi , xi tong yao cha kan shi fou huan you ling yi ge you xian ji wei 31 de xian cheng ke yi yun xing , ru guo you , ta jiang yuan xu gai xian cheng bei fu yu yi ge CPU。 zhi yao you xian ji wei 31 de xian cheng shi ke tiao du de , xi tong jiu jue dui bu hui jiang you xian ji wei 0 dao 30 de xian cheng fen pei gei C P U。 zhe zhong qing kuang cheng wei ke qiu tiao du (starvation)。 dang gao you xian ji xian cheng shi yong da liang de CPU shi jian , cong er shi de di you xian ji xian cheng wu fa yun xing shi , bian hui chu xian ke qiu qing kuang 。 zai duo chu li qi ji suan ji shang chu xian ke qiu qing kuang de ke neng xing yao shao de duo , yin wei zai zhe yang de ji suan ji shang , you xian ji wei 31 he you xian ji wei 30 de xian cheng neng gou tong shi yun xing 。 xi tong zong shi she fa shi CPU bao chi fan mang zhuang tai , zhi you dang mei you xian cheng ke yi tiao du de shi hou , CPU cai chu yu kong xian zhuang tai 。 ren men ke neng ren wei , zai zhe yang de xi tong zhong , di you xian ji xian cheng yong yuan de bu dao ji hui yun xing 。 bu guo zheng xiang qian mian zhi chu de na yang , zai ren he yi ge shi duan nei , xi tong zhong de da duo shu xian cheng shi bu neng tiao du de 。 li ru , ru guo jin cheng de zhu xian cheng tiao yong GetMessage han shu , er xi tong fa xian mei you xian cheng ke yi gong ta shi yong , na me xi tong jiu zan ting jin cheng de xian cheng yun xing , shi fang gai xian cheng de sheng yu shi jian pian , bing qie li ji jiang CPU fen pei gei ling yi ge deng dai yun xing de xian cheng 。 ru guo mei you wei GetMessage han shu xian shi ke gong jian suo de xiao xi , na me jin cheng de xian cheng jiang bao chi zan ting zhuang tai , bing qie jue bu hui bei fen pei gei CPU。 dan shi , dang xiao xi bei zhi yu xian cheng de dui lie zhong shi , xi tong jiu zhi dao gai xian cheng bu ying gai zai chu yu zan ting zhuang tai 。 ci shi , ru guo mei you geng gao you xian ji de xian cheng xu yao yun xing , xi tong jiu jiang gai xian cheng fen pei gei yi ge CPU。 gao you xian ji xian cheng jiang qiang zai di you xian ji xian cheng zhi qian yun xing , bu guan di you xian ji xian cheng zheng zai yun xing shen me 。 li ru , ru guo yi ge you xian ji wei 5 de xian cheng zheng zai yun xing , xi tong fa xian yi ge gao you xian ji de xian cheng zhun bei yao yun xing , na me xi tong jiu hui li ji zan ting di you xian ji xian cheng de yun xing ( ji shi ta chu yu ta de shi jian pian zhong ), bing qie jiang C P U fen pei gei gao you xian ji xian cheng , shi ta huo de yi ge wan zheng de shi jian pian 。 huan you , dang xi tong yin dao shi , ta hui chuang jian yi ge te shu de xian cheng , cheng wei 0 ye xian cheng 。 gai xian cheng bei fu yu you xian ji 0, ta shi zheng ge xi tong zhong wei yi de yi ge zai you xian ji 0 shang yun xing de xian cheng 。 dang xi tong zhong mei you ren he xian cheng xu yao zhi xing cao zuo shi ,0 ye xian cheng fu ze jiang xi tong zhong de suo you kong xian R A M ye mian zhi 0。 dong tai ti gao xian cheng de you xian ji deng ji tong guo jiang xian cheng de xiang dui you xian ji yu xian cheng de jin cheng you xian ji lei zong he qi lai kao lv , xi tong jiu ke yi que ding xian cheng de you xian ji deng ji 。 you shi zhe cheng wei xian cheng de ji ben you xian ji deng ji 。 xi tong chang chang yao ti gao xian cheng de you xian ji deng ji , yi bian dui chuang kou xiao xi huo du qu ci pan deng I/O shi jian zuo chu xiang ying 。 li ru , zai gao you xian ji lei jin cheng zhong de yi ge zheng chang you xian ji deng ji de xian cheng de ji ben you xian ji deng ji shi 13。 ru guo yong hu an xia yi ge cao zuo jian , xi tong jiu hui jiang yi ge WM_KEYDOWN xiao xi fang ru xian cheng de dui lie zhong 。 you yu yi ge xiao xi yi jing chu xian zai xian cheng de dui lie zhong , yin ci gai xian cheng jiu shi ke tiao du de xian cheng 。 ci wai , jian pan she bei qu dong cheng xu ye neng gou gao su xi tong zan shi ti gao xian cheng de you xian ji deng ji 。 gai xian cheng de you xian ji deng ji ke neng ti gao 2 ji , qi dang qian you xian ji deng ji gai wei 15。 xi tong zai you xian ji wei 15 shi wei yi ge shi jian pian dui gai xian cheng jin xing tiao du 。 yi dan gai shi jian pian jie shu , xi tong bian jiang xian cheng de you xian ji di jian 1, shi xia yi ge shi jian pian de xian cheng you xian ji jiang wei 14。 gai xian cheng de di san ge shi jian pian an you xian ji deng ji 13 lai zhi xing 。 ru guo xian cheng yao qiu zhi xing geng duo de shi jian pian , yun an ta de ji ben you xian ji deng ji 13 lai zhi xing 。 zhu yi , xian cheng de dang qian you xian ji deng ji jue bu hui di yu xian cheng de ji ben you xian ji deng ji 。 ci wai , dao zhi xian cheng cheng wei ke tiao du xian cheng de she bei qu dong cheng xu ke yi jue ding you xian ji deng ji ti gao de shu liang 。Microsoft bing mei you gui ding ge ge she bei qu dong cheng xu ke yi gei xian cheng de you xian ji ti gao duo shao ge deng ji 。 zhe yang jiu shi de Microsoft ke yi bu duan di tiao zheng xian cheng you xian ji ti gao de dong tai deng ji , yi que ding zui jia de zong ti xiang ying xing neng 。 xi tong zhi neng wei ji ben you xian ji deng ji zai 1 zhi 15 zhi jian de xian cheng ti gao qi you xian ji deng ji 。 shi ji shang zhe shi yin wei zhe ge fan wei cheng wei dong tai you xian ji fan wei 。 ci wai , xi tong jue bu hui jiang xian cheng de you xian ji deng ji ti gao dao shi shi fan wei ( gao yu 15)。 you yu shi shi fan wei zhong de xian cheng neng gou zhi xing da duo shu cao zuo xi tong de han shu , yin ci gei deng ji de ti gao gui ding yi ge fan wei , jiu ke yi fang zhi ying yong cheng xu gan rao cao zuo xi tong de yun xing 。 ling wai , xi tong jue bu hui dong tai ti gao shi shi fan wei nei de xian cheng you xian ji deng ji 。 ling yi zhong qing kuang ye hui dao zhi xi tong dong tai di ti gao xian cheng de you xian ji deng ji 。 bi ru you yi ge you xian ji wei 4 de xian cheng zhun bei yun xing dan shi que bu neng yun xing , yin wei yi ge you xian ji wei 8 de xian cheng zheng lian xu bei tiao du 。 zai zhe zhong qing kuang xia , you xian ji wei 4 de xian cheng jiu fei chang ke wang de dao CPU shi jian 。 dang xi tong fa xian yi ge xian cheng zai da yue 3 zhi 4s nei yi zhi ke wang de dao C P U shi jian , ta jiu jiang zhe ge ke wang de dao CPU shi jian de xian cheng de you xian ji dong tai ti gao dao 15, bing rang gai xian cheng yun xing liang bei yu ta de shi jian liang 。 dang dao le liang bei shi jian liang de shi hou , gai xian cheng de you xian ji li ji fan hui dao ta de ji ben you xian ji 。 xi tong dong tai de gai bian you xian ji , zai wo men bian cheng de shi hou hui chan sheng bu liang ying xiang , wei ci , huan you liang ge API han shu ke yi shi de xi tong de ci gong neng bu qi zuo yong 。 bool SetProcessPriorityBoost(HANDLE hProcess,bool disablePriorityboost); bool SetThreadPriorityBoost(HANDLE hThread,bool disablePriorityboost); cong ming zi ni jiu ying gai ke yi kan chu , di yi ge API han shu ke yi ji huo huo ting yong zhi ding jin cheng suo you xian cheng de you xian ji ti gao gong neng , er hou mian yi ge ze shi zhen dui te ding xian cheng de 。 li zi : guan jian de dai ma ru xia [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{ [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/url] zuo zhe :wudi_1982 [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/url] lian xi fang shi :wudi_1982@hotmail.com [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/url] zhuan zai qing zhu ming chu chu [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/url] ben dai ma zhi zai yan shi xian cheng de tiao du , hen duo wei zhi mei you jia ru shi dang de kong zhi he zi yuan shi fang , qing an zhao hou xu cao zuo zhi xing [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif[/img][/url]} [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]type [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TSleepType=(stSleep,stSwitch); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // yan shi xian cheng tiao du de TThread pai sheng lei [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TPriThread1=class(TThread) [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] private [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] CurCount : integer; // dang qian ji shu [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Flb : TLabel; // yong lai xian shi dang qian ji shu de label [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FCanSleep : Boolean; // shi fou zi dong shi fang shi jian pian [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FSleepMs : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FSleepType : TSleepType;// shi fang shi jian pian de fang shi [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure GetRestult; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] protected [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure Execute;override; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] public [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] constructor Create(CreateSuspended: Boolean;ALabel : TLabel); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property CanSleep : boolean read FCanSleep write FCanSleep; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property SleepMs : integer read FSleepMs write FSleepMs; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property SleepType : TSleepType read FSleepType write FSleepType; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url].... [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{ TPriThread1 de shi xian } [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]constructor TPriThread1.Create(CreateSuspended: Boolean; ALabel: TLabel); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]// gou zao han shu [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] flb := ALabel; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FSleepMs := 0; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FCanSleep := true; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FSleepType := stSleep; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] inherited create(CreateSuspended); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TPriThread1.Execute; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] i : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] inherited; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FreeOnTerminate := true; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] CurCount := 0; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for i := 0 to 100000 do [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] CurCount := i;// gai bian dang qian ji shu [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Synchronize(GetRestult);// xian shi jie guo [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if FCanSleep then// shi fou zi dong shi fang shi jian pian [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // gen ju shi fang shi jian pian de bu tong fang shi jin xing xiang ying cao zuo [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] case FSleepType of [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] stSleep : Sleep(SleepMs);// shui mian [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] stSwitch : SwitchToThread;// tiao yong qi ta xian cheng [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TPriThread1.GetRestult; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] flb.Caption := IntToStr(CurCount); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{Form1 de zhu yao dai ma } [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.btnPThread1CreateClick(Sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // sheng cheng liang ge xian cheng [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread1 := TPriThread1.Create( not ckbx1State.Checked,lab1); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread2 := TPriThread1.Create(not ckbx2State.Checked,lab2); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // de dao ta men dang qian de you xian ji [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] lb1p.Caption := inttostr(GetThreadPriority(MyPThread1.Handle)); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] lb2p.Caption := inttostr(GetThreadPriority(MyPThread2.Handle)); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.btnPThread1ResClick(Sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // zhi xing xian cheng [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread1.Resume; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ckbx1State.Checked := true; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread2.Resume; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ckbx2State.Checked := true; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.btnPThread1SudClick(Sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // gua qi xian cheng [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread1.Suspend; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ckbx1State.Checked := false; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread2.Suspend; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ckbx2State.Checked := false; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.btnUpPThread1Click(Sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // zai xian cheng gua qi shi , ti gao di yi ge xian cheng de xiang dui you xian ji [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread1.Priority := tpHigher; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // xian shi dang qian de you xian ji dao ping mu [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] lb1p.Caption := inttostr(GetThreadPriority(MyPThread1.Handle)); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // MyPThread2.Priority := tpHigher; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.btnUpdateSleepClick(Sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // xiu gai liang ge xian cheng de shi jian pian shi fang fang shi [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread1.CanSleep := ckbxAllowSleep1.Checked; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] case RadioGroup1.ItemIndex of [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] 0 : MyPThread1.SleepType := stSleep; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] 1 : MyPThread1.SleepType := stSwitch; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyPThread2.CanSleep := ckbxAllowSleep2.Checked; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] case RadioGroup2.ItemIndex of [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] 0 : MyPThread2.SleepType := stSleep; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] 1 : MyPThread2.SleepType := stSwitch; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] chuang ti xiao guo : [url=http://www.wangchao.net.cn/bbs/pydetail_566835.html][img]http://p.blog.csdn.net/images/p_blog_csdn_net/wudi_1982/ xian cheng tiao du cheng xu yan shi jie mian .JPG[/img][/url] rang wo men lai yong zhe ge cheng xu ce shi yi xie xiao guo : 1、 ji ben zhi xing 。 cheng xu yun xing zhi hou , shi yong mo ren she zhi , dian ji 【 chuang jian xian cheng 】 an niu , xian cheng jiang bei chuang jian , bing qie gua qi , zhe shi ni ke yi jian ge de dian ji 【 zhi xing xian cheng 】 he 【 gua qi xian cheng 】 an niu , ni hui zai ping mu shang kan dao xian cheng de dang qian ji shu , zhu yi zhe liang ge ji shu zhi jian de cha zhi , yi ji zheng ge jie mian de zhi xing xiao guo ( wo zhi de shi zai ni rang xian cheng bu duan de zhi xing he gua qi zhi jian jie mian shi fou hui chu xian bu shua xin de qing kuang ), dang xian cheng zhi xing wan bi zhi hou , guan bi cheng xu 。 2、 tong guo Sleep(0) shi fang shi jian pian yan shi xian cheng tiao du 。 yun xing cheng xu , shi yong mo ren she zhi , dian ji 【 chuang jian xian cheng 】 an niu , ran hou jiang liang ge xian cheng de zi shi fang shi jian pian gong neng tong tong qu diao ( ye jiu shi qu diao ckbxAllowSleep1 and 2 de gou gou ), ran hou dian ji 【 xiu gai shui mian fang shi 】 an niu , sui hou ni ke yi jin xing jian ge dian ji 【 zhi xing xian cheng 】 he 【 gua qi xian cheng 】 an niu , duo zuo ji ci zhe yang de cao zuo , guan cha liang ge ji shu zhi jian de cha zhi , he ce shi 1 de cha zhi bi jiao yi xia 。 wo xiang ni ying gai neng xiang dao xie shen me 。 ran hou , ji hu ke yi ken ding ni de jie mian jiang hui chu xian wu fa shua xin de qing kuang , bing qie ni de shu biao wu fa li ji zai ci jie mian shang jin xing qi ta de cao zuo 。 zhe ge shi hou , shao deng yi xia , ni hui fa xian guo le yi hui er , liang ge dang qian ji shu dou bei shua xin le 。 wei shen me ?? zhe shi , wo men chu le kao lv wo men chuang jian de liang ge xian cheng zhi wai , ni huan yao kao lv de ni cheng xu ben shen de zhu xian cheng yi ji qi ta ke neng cun zai de fu shu xian cheng , wo men zai qu cheng xu zhong xian cheng de na duan xun huan dai ma , CurCount := i;// gai bian dang qian ji shu Synchronize(GetRestult);// xian shi jie guo if FCanSleep then// shi fou zi dong shi fang shi jian pian begin // gen ju shi fang shi jian pian de bu tong fang shi jin xing xiang ying cao zuo case FSleepType of stSleep : Sleep(SleepMs);// shui mian stSwitch : SwitchToThread;// tiao yong qi ta xian cheng end; end; ni ying gai kan dao xian cheng jiang dang qian ji shu xian shi zai ping mu shang de cao zuo shi zhi xing le Synchronize(GetRestult), zhe li , yin wei wo men de xian cheng he VCL jie mian fa sheng le jiao hu , wo men bi xu dui Synchronize you suo le jie , qu kan VCL de yuan ma , ni hui fa xian , dang ni zai cheng xu zhong di yi ci chuang jian yi ge fu shu xian cheng shi , VCL jiang hui cong zhu xian cheng huan jing zhong chuang jian he wei hu yi ge yin han de xian cheng chuang kou 。 ci chuang kou wei yi de mu de shi ba tong guo Synchronize() tiao yong de fang fa pai dui 。Synchronize() ba you Method shen shu chuan di guo lai de fang fa bao cun zai TThread de FMethod zi duan zhong , ran hou , gei xian cheng chuang kou fa yi ge CM_EXECPROC xiao xi , bing qie ba xiao xi de lParam shen shu she wei self( zhe li zhi xian cheng dui xiang )。 dang xian cheng chuang kou de chuang kou guo cheng shou dao zhe ge xiao xi hou , ta jiu tiao yong FMethod zi duan suo zhi ding de fang fa 。 you yu xian cheng chuang kou shi zai zhu xian cheng nei chuang jian de , xian cheng chuang kou de chuang kou guo cheng ye jiang bei zhu xian cheng zhi xing 。 yin ci ,FMethod zi duan suo zhi ding de fang fa jiu zai zhu xian cheng nei zhi xing 。 zai wo men xuan ze shi fang shi jian pian de mo shi xia , zai zhe li , wu lun wo men shi yong Sleep huan shi SwitchToThread, dang qian xian cheng dou hui li ji shi fang shi jian pian , yin wei zhe shi wo men bing mei you xiu gai xian cheng de you xian ji , ta men dou zai tong yang de you xian ji huan jing xia yun xing , na me dang zhan yong CPU de xian cheng shi fang shi jian pian hou , qi ta xian cheng jiang ke yi xiang dui qing song de de dao CPU, suo yi zai shi yong shi fang shi jian pian de mo shi xia , jie mian de shua xin hui liang hao 。 bing qie tiao du xiang dui you xu 。 3、Sleep he SwitchToThread qu bie de yan shi 。 yun xing cheng xu , shi yong mo ren she zhi , dian ji 【 chuang jian xian cheng 】 an niu , ran hou dian ji 【 ti gao xian cheng 1 de you xian ji 】 an niu , zai dian ji 【 zhi xing xian cheng 】 zhe shi , liang ge xian cheng jiang bu zai shi tong yang de you xian ji , qi ta she zhi yi ran shi mo ren de ( shi yong sleep fang shi shi fang shi jian pian ), ni hui kan dao xian cheng 1 shou xian zhi xing , xian cheng 2 chu yu ke tiao du mo shi , dan bing mei you bei tiao du ( dang qian ji shu mei you shua xin ), bing qie ping mu ye bu shua xin , zai shao deng yi duan shi jian zhi hou , ping mu shua xin , xian cheng 2 ye kai shi yun xing , bing qie ci shi ping mu shua xin zheng chang 。 wei shen me ne ? hui tou qu kan ben wen shang mian de nei rong , dang xian cheng 1 de you xian ji ti gao zhi hou , xi tong hui shou xian tiao du ta , sui ran ta shi yong sleep(0) lai shi fang shi jian pian , dan dang shi jian pian shi fang hou , yin wei ta de you xian ji xiang dui jiao gao , xi tong yi ran hui tiao du xian cheng 1, suo yi ci shi , xian cheng 2 jiang bu neng zhi xing , jie mian ye bu neng you xiao shua xin 。 zai zhe ge si lu xia , zai zuo yi ge ce shi , shi yong tong yang de fang shi , zhi bu guo zhe ci , zai xian cheng zhi xing zhi qian , chu le ti gao xian cheng 1 de you xian ji zhi wai , huan jiang xian cheng 1 shi fang shi jian pian fang shi gai wei SwitchToThread, ci shi ni jiu ke yi kan dao liang ge xian cheng dou you ji hui zhi xing , bing qie jie mian ye jiang you xiao shua xin 。 4、 ni huan ke yi zuo qi ta pei zhi xin xi de ce shi , xiang xin hui jia shen dui WIN32 ping tai xia xian cheng tiao du de le jie 。 shen kao wen xian 1、《DELPHI5 kai fa ren yuan zhi nan 》 2、《WINDOWS gai xin bian cheng 》 zhu : yi shang cheng xu zai D7+WINXP xia ce shi tong guo zhuan zai qing zhu ming chu chu 。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
情人节的清纯女生(9)
情人节的清纯女生(8)
情人节的清纯女生(7)
情人节的清纯女生(6)
山东蓬莱海边组照
一探哲蚌 II
一探哲蚌 III
古长城的一角
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有