⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csdn_文档中心_win32多线程程序设计学习笔记(第四章 下 第五章).htm

📁 csdn10年中间经典帖子
💻 HTM
📖 第 1 页 / 共 5 页
字号:
            face=宋体><FONT size=2><B><SPAN lang=EN-US 
            style="COLOR: green">hExitEvent</SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不是总处于未激发状态吗?哪线程不就停在这里不动了?</SPAN><SPAN 
            lang=EN-US 
            style="COLOR: green"><o:p></o:p></SPAN></B></FONT></FONT></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><FONT 
            size=2><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">答案是:这里用到了</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>P74</FONT></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提到的一个</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>Wait….()</FONT></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一个用法,当</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>time_out<o:p></o:p></FONT></SPAN></B></FONT></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><FONT 
            size=2><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>0</FONT></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,检查</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>hExitEvent</FONT></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的状态,如果</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>hExitEvent</FONT></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">处于未激发状态,</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><o:p></o:p></SPAN></B></FONT></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><FONT 
            size=2><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">立刻返回</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>WAIT_TIMEOUT</FONT></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,如果</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>hExitEvent</FONT></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">处于激发状态,则立刻</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><o:p></o:p></SPAN></B></FONT></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><FONT 
            size=2><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">返回</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>WAIT_OBJECT_0</FONT></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN><SPAN 
            lang=EN-US style="COLOR: green"><FONT 
            face=宋体>*/<o:p></o:p></FONT></SPAN></B></FONT></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT size=2>if ( WaitForSingleObject ( 
            hExitEvent , 0 ) !=WAIT_TIMEOUT 
            )<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT 
            size=2>{<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><FONT 
            face=宋体><FONT size=2><B><SPAN lang=EN-US><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">做一些退出线程前的清理工作</SPAN><SPAN 
            lang=EN-US 
            style="COLOR: green"><o:p></o:p></SPAN></B></FONT></FONT></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT size=2><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>return (DWORD) –1 ;<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT 
            size=2>}<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face=宋体><FONT 
            size=2><B><SPAN lang=EN-US><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">做一些极其消耗时间的处理</SPAN><SPAN 
            lang=EN-US 
            style="COLOR: green">….<o:p></o:p></SPAN></B></FONT></FONT></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US 
            style="COLOR: green"><FONT face=宋体><FONT size=2><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>//…….<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><FONT 
            face=宋体><FONT size=2><SPAN lang=EN-US style="COLOR: green"><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>//……..</SPAN><SPAN 
            lang=EN-US><o:p></o:p></SPAN></FONT></FONT></B></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT size=2><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>}<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT 
            size=2>}<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT size=2>void 
            main()<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT size=2>{<SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN><o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face=宋体><FONT 
            size=2><B><SPAN lang=EN-US><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>HANDLE </SPAN></B><B><SPAN lang=EN-US 
            style="FONT-SIZE: 10pt; mso-bidi-font-size: 12.0pt">hThrd;<o:p></o:p></SPAN></B></FONT></FONT></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><FONT 
            face=宋体><FONT size=2><B><SPAN lang=EN-US 
            style="COLOR: green">//</SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">构造</SPAN><SPAN 
            lang=EN-US style="COLOR: green">EVENT</SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">核心对象</SPAN><SPAN 
            lang=EN-US style="COLOR: green">,</SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">初始状态处于未激发状态,</SPAN><SPAN 
            lang=EN-US style="COLOR: green">Manual</SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方式</SPAN><SPAN 
            lang=EN-US 
            style="COLOR: green"><o:p></o:p></SPAN></B></FONT></FONT></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN 
            lang=EN-US><FONT face=宋体><FONT size=2><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>hExitEvent = CreateEvent ( NULL,TRUE,FALSE,NULL ) 
            ;<o:p></o:p></FONT></FONT></SPAN></B></P>
            <P class=MsoNormal 
            style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><FONT 
            face=宋体><FONT size=2><B><SPAN lang=EN-US 
            style="COLOR: green">//</SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">线程启动</SPAN><SPAN 
            lang=EN-US 
            style="COLOR: green"><o:p></o:p></SPAN></B></FONT></FONT></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face=宋体><FONT 
            size=2><B><SPAN lang=EN-US><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN></SPAN></B><B><SPAN lang=EN-US 
            style="FONT-SIZE: 10pt; mso-bidi-font-size: 12.0pt">hThrd<SPAN 
            style="mso-spacerun: yes">&nbsp; </SPAN>= CreateThread ( null<SPAN 
            style="COLOR: blue">,ThreadFun</SPAN>,…..);</SPAN><SPAN 
            lang=EN-US><o:p></o:p></SPAN></B></FONT></FONT></P>
            <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face=宋体><FONT 
            size=2><B><SPAN lang=EN-US><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN></B><B><SPAN 
            style="COLOR: green; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等待了很久,实在等不下去了,发出结束线程退出事件(激发</SPAN><SPAN 
            lang=EN-US style="COLOR: green">EVENT</SPAN></B><B><SPAN 
            style="COLOR: green; FON

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -