亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch27.htm

?? Learning language of Visual C++6
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
<SCRIPT LANGUAGE="JavaScript">

<!--

function popUp(pPage) {
 var fullURL = document.location;
 var textURL = fullURL.toString();
 var URLlen = textURL.length;
 var lenMinusPage = textURL.lastIndexOf("/");
 lenMinusPage += 1;
 var fullPath = textURL.substring(0,lenMinusPage);
 popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
 figDoc= popUpWin.document;
 zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
 zhtm += '<link rel="stylesheet" href="/includes/stylesheets/ebooks.css"></head>';
 zhtm += '<BODY bgcolor="#FFFFFF">';
 zhtm += '<IMG SRC="' + fullPath + pPage + '">';
 zhtm += '<P><B>' + pPage + '</B>';
 zhtm += '</BODY></HTML>';
 window.popUpWin.document.write(zhtm);
 window.popUpWin.document.close();
 // Johnny Jackson 4/28/98
 }

//-->
                                                                
</SCRIPT>
<link rel="stylesheet" href="/includes/stylesheets/ebooks.css">

	
	<TITLE>Special Edition Using Visual C++ 6 -- Ch 27 -- Multitasking with Windows Threads</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<CENTER>
<H1><IMG SRC="../button/que.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR>
Special Edition Using Visual C++ 6</H1>
</CENTER>
<CENTER>
<P><A HREF="../ch26/ch26.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch28/ch28.htm"><IMG
SRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> 
<HR>

</CENTER>
<CENTER>
<H1>- 27 -</H1>
</CENTER>
<CENTER>
<H1>Multitasking with Windows Threads</H1>
</CENTER>

<UL>
	<LI><A HREF="#Heading1">Understanding Simple Threads</A>
	<LI><A HREF="#Heading2">Understanding Thread Communication</A>
	<UL>
		<LI><A HREF="#Heading3">Communicating with Global Variables</A>
		<LI><A HREF="#Heading4">Communicating with User-Defined Messages</A>
		<LI><A HREF="#Heading5">Communicating with Event Objects</A>
	</UL>
	<LI><A HREF="#Heading6">Using Thread Synchronization</A>
	<UL>
		<LI><A HREF="#Heading7">Using Critical Sections</A>
		<LI><A HREF="#Heading8">Using Mutexes</A>
		<LI><A HREF="#Heading9">Using Semaphores</A>
	</UL>
</UL>

<P>
<HR SIZE="4">

<CENTER>
<H1></H1>
</CENTER>
<P>When using Windows 95 (and other modern operating systems), you know that you
can run several programs simultaneously. This capability is called <I>multitasking.</I>
What you may not know is that many of today's operating systems also enable <I>threads,</I>
which are separate processes that are not complete applications. A thread is a lot
like a subprogram. An application can create several threads--several different flows
of execution--and run them concurrently. Threads give you the ability to have multitasking
inside multitasking. The user knows that he can run several applications at a time.
The programmer knows that each application can run several threads at a time. In
this chapter, you'll learn how to create and manage threads in your applications.</P>
<P>
<H2><A NAME="Heading1"></A>Understanding Simple Threads</H2>
<P>A thread is a path of execution through a program. In a multithreaded program,
each thread has its own stack and operates independently of other threads running
within the same program. MFC distinguishes between <I>UI threads</I>, which have
a message pump and typically perform user interface tasks, and <I>worker threads</I>,
which do not.</P>


<BLOCKQUOTE>
	<P>
<HR>
<strong>NOTE:</strong> Any application always has at least one thread, which is the program's
	primary or main thread. You can start and stop as many additional threads as you
	need, but the main thread keeps running as long as the application is active.&#160;
	
<HR>


</BLOCKQUOTE>

<P>A thread is the smallest unit of execution, much smaller than a <I>process</I>.
Generally each running application on your system is a process. If you start the
same application (for example, Notepad) twice, there will be two processes, one for
each instance. It is possible for several instances of an application to share a
single process: for example, if you choose File, New Window in Internet Explorer,
there are two applications on your taskbar, and they share a process. The unfortunate
consequence is that if one instance crashes, they all do.</P>
<P>To create a worker thread using MFC, all you have to do is write a function that
you want to run parallel with the rest of your application. Then call AfxBeginThread()
to start a thread that will execute your function. The thread remains active as long
as the thread's function is executing: When the thread function exits, the thread
is destroyed. A simple call to AfxBeginThread() looks like this:</P>
<P>
<PRE>AfxBeginThread(ProcName, param, priority);
</PRE>
<P>In the preceding line, ProcName is the name of the thread's function, param is
any 32-bit value you want to pass to the thread, and priority is the thread's priority,
which is represented by a number of predefined constants. Table 27.1 shows those
constants and their descriptions.</P>
<P>
<H4>Table 27.1&#160;&#160;Thread Priority Constants</H4>
<P>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT"><B>Constant</B></TD>
		<TD ALIGN="LEFT"><B>Description</B></TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">THREAD_PRIORITY_ABOVE_NORMAL</TD>
		<TD ALIGN="LEFT">Sets a priority one point higher than normal.</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">THREAD_PRIORITY_BELOW_NORMAL</TD>
		<TD ALIGN="LEFT">Sets a priority one point lower than normal.</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">THREAD_PRIORITY_HIGHEST</TD>
		<TD ALIGN="LEFT">Sets a priority two points above normal.</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">THREAD_PRIORITY_IDLE</TD>
		<TD ALIGN="LEFT">Sets a base priority of 1. For a REALTIME_PRIORITY_CLASS process, this sets a priority
			of 16.</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">THREAD_PRIORITY_LOWEST</TD>
		<TD ALIGN="LEFT">Sets a priority two points below normal.</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">THREAD_PRIORITY_NORMAL</TD>
		<TD ALIGN="LEFT">Sets normal priority.</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">THREAD_PRIORITY_TIME_CRITICAL</TD>
		<TD ALIGN="LEFT">Sets a base priority of 15. For a REALTIME_PRIORITY_CLASS process, this sets a priority
			of 30.</TD>
	</TR>
</TABLE>



<BLOCKQUOTE>
	<P>
<HR>
<strong>NOTE:</strong> A thread's priority determines how often the thread takes control
	of the system, relative to the other running threads. Generally, the higher the priority,
	the more running time the thread gets, which is why the value of THREAD_PRIORITY_TIME_CRITICAL
	is so high.&#160;
<HR>


</BLOCKQUOTE>

<P>To see a simple thread in action, build the Thread application as detailed in
the following steps.</P>

<DL>
	<DT></DT>
	<DD><B>1. </B>Start a new AppWizard project workspace called <B>Thread</B>, as shown
	in Figure 27.1.
	<P>
</DL>

<P><A HREF="javascript:popUp('27uvc01.gif')"><B>FIG. 27.1</B></A><B> </B><I>Start
an AppWizard project workspace called </I><B>Thread</B><I>.</I></P>

<DL>
	<DT><I></I></DT>
	<DD><B>2. </B>Give the new project the following settings in the AppWizard dialog
	boxes. The New Project Information dialog box will then look like Figure 27.2.
	<P>
</DL>



<BLOCKQUOTE>
	<P>Step 1: Single document</P>

	<P>Step 2: Default settings</P>

	<P>Step 3: Default settings</P>

	<P>Step 4: Turn off all options</P>

	<P>Step 5: Default settings</P>

	<P>Step 6: Default settings</P>

</BLOCKQUOTE>

<P><A HREF="javascript:popUp('27uvc02.gif')"><B>FIG. 27.2</B></A><B> </B><I>These
are the AppWizard settings for the Thread project.</I></P>

<DL>
	<DT><I></I></DT>
	<DD><B>3. </B>Use the resource editor to add a Thread menu to the application's IDR_MAINFRAME
	menu. Give the menu one command called <B>Start Thread</B> with a command ID of <B>ID_STARTTHREAD</B>,
	and enter a sensible prompt and ToolTip, as shown in Figure 27.3.
	<P>
</DL>

<P><A HREF="javascript:popUp('27uvc03.gif')"><B>FIG. 27.3</B></A><B> </B><I>Add a
Thread menu with a Start Thread command.</I></P>

<DL>
	<DD><B>4. </B>Use ClassWizard to associate the ID_STARTTHREAD command with the OnStartthread()
	message-response function, as shown in Figure 27.4. Make sure that you have <B>CThreadView</B>
	selected in the Class Name box before you add the function.
	<P>
</DL>

<P><A HREF="javascript:popUp('27uvc04.gif')"><B>FIG. 27.4</B></A><B> </B><I>Add the
OnStartthread() message-response function to the view class.</I></P>

<DL>
	<DT><I></I></DT>
	<DD><B>5. </B>Click the Edit Code button and then add the following lines to the
	new OnStartthread() function, replacing the TODO: Add your command handler code here
	comment:
	<P>
</DL>

<PRE>    HWND hWnd = GetSafeHwnd();
    AfxBeginThread(ThreadProc, hWnd, THREAD_PRIORITY_NORMAL);
</PRE>
<P>This code will call a function called ThreadProc within a worker thread of its
own. Next, add ThreadProc, shown in Listing 27.1, to ThreadView.cpp, placing it right
before the OnStartthread() function. Note that ThreadProc() is a global function
and not a member function of the CThreadView class, even though it is in the view
class's implementation file.</P>
<P>
<H4>Listing 27.1&#160;&#160;ThreadView.cpp--ThreadProc()</H4>
<PRE>UINT ThreadProc(LPVOID param)
{
    ::MessageBox((HWND)param, &quot;Thread activated.&quot;, &quot;Thread&quot;, MB_OK);
    return 0;
</PRE>
<PRE>}
</PRE>
<P>This threaded function doesn't do much, just reports that it was started. The
SDK function MessageBox() is very much like AfxMessageBox(), but because this isn't
a member function of a class derived from CWnd, you can't use AfxMessageBox().</P>


<BLOCKQUOTE>
	<P>
<HR>
<strong>TIP:</strong> The double colons in front of a function name indicate a call to a
	global function, instead of an MFC class member function. For Windows programmers,
	this usually means an API or SDK call. For example, inside an MFC window class, you
	can call MessageBox(&quot;Hi, There!&quot;) to display <I>Hi, There!</I> to the user.
	This form of MessageBox() is a member function of the MFC window classes. To call
	the original Windows version, you write something like ::MessageBox(0, &quot;Hi,
	There!&quot;, &quot;Message&quot;, MB_OK). Notice the colons in front of the function
	name and the additional arguments. 
<HR>


</BLOCKQUOTE>

<P>When you run the Thread program, the main window appears. Select the Thread, Start<B>
</B>Thread command, and the system starts the thread represented by the ThreadProc()
function and displays a message box, as shown in Figure 27.5.</P>
<P><A HREF="javascript:popUp('27uvc05.gif')"><B>FIG. 27.5</B></A><B> </B><I>The simple
secondary thread in the Thread program displays a message box and then ends.</I></P>

<P><I></I>
<H2><A NAME="Heading2"></A>Understanding Thread Communication</H2>
<P>Usually, a secondary thread performs some sort of task for the main program, which
implies that there needs to be a channel of communication between the program (which
is also a thread) and its secondary threads. There are several ways to accomplish
these communications tasks: with global variables, event objects, and messages. In
this section, you'll explore these thread-communication techniques.</P>
<P>
<H3><A NAME="Heading3"></A>Communicating with Global Variables</H3>
<P>Suppose you want your main program to be able to stop the thread. You need a way,
then, to tell the thread when to stop. One method is to set up a global variable
and then have the thread monitor the global variable for a value that signals the
thread to end. Because the threads share the same address space, they have the same
global variables. To see how this technique works, modify the Thread application
as follows:</P>

<DL>
	<DT></DT>
	<DD><B>1. </B>Use the resource editor to add a <B>Stop Thread</B> command to the
	application's Thread menu. Give this new command the <B>ID_STOPTHREAD</B> ID, as
	shown in Figure 27.6.
</DL>

<P><A HREF="javascript:popUp('27uvc06.gif')"><B>FIG. 27.6</B></A><B> </B><I>Add a

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品国产sm最大网站| 亚洲国产日韩综合久久精品| 亚洲天堂免费在线观看视频| 蜜臀av性久久久久蜜臀aⅴ流畅| 国产成a人亚洲精品| 欧美日韩1区2区| 中文字幕日韩精品一区| 久久99国产精品麻豆| 欧美在线免费观看亚洲| 久久久国产精华| 日本成人在线不卡视频| 色综合一个色综合亚洲| 国产精品免费久久| 韩国一区二区视频| 欧美二区三区91| 亚洲福利视频一区二区| 一本大道久久a久久综合婷婷| 国产亚洲精品中文字幕| 精品一区二区免费在线观看| 欧美男男青年gay1069videost | 99热精品国产| 日本一区二区高清| 国产揄拍国内精品对白| 久久美女艺术照精彩视频福利播放| 午夜精品成人在线| 欧美在线观看视频一区二区| 亚洲人成影院在线观看| 97精品国产露脸对白| 国产精品美女一区二区| 夫妻av一区二区| 久久久久久久综合日本| 国产精品亚洲成人| 久久久久久久久一| 国产成人免费视频网站| 国产欧美精品区一区二区三区 | 91丨porny丨在线| 中文字幕综合网| 色哟哟一区二区三区| 亚洲免费在线播放| 欧美三级午夜理伦三级中视频| 亚洲综合小说图片| 欧美久久高跟鞋激| 久久精品国产免费| 国产午夜精品美女毛片视频| 国产成人免费9x9x人网站视频| 中文一区二区在线观看 | 国产九九视频一区二区三区| 久久久精品一品道一区| 成人av网站在线观看| 亚洲激情男女视频| 7777精品伊人久久久大香线蕉 | 精品人在线二区三区| 国产一区二区三区久久久| 欧美激情一区二区在线| 色老头久久综合| 奇米色一区二区| 国产欧美日韩视频在线观看| 91麻豆精东视频| 青青草伊人久久| 国产欧美日韩在线观看| 欧美日韩精品一区二区三区| 国产一区二区三区四区五区美女| 国产精品国产三级国产专播品爱网 | 亚洲国产精品嫩草影院| 日韩欧美一级精品久久| 成人福利在线看| 日韩av电影一区| 国产精品久久久久桃色tv| 欧美日韩久久一区| 成人一道本在线| 日韩 欧美一区二区三区| 国产精品美女一区二区三区| 91精品国产综合久久福利软件| 国产丶欧美丶日本不卡视频| 亚洲一区二区美女| 中文一区二区完整视频在线观看| 欧美肥大bbwbbw高潮| 99精品久久只有精品| 久久国产精品第一页| 亚洲国产色一区| 亚洲欧洲日韩在线| 欧美成人aa大片| 欧美三级日韩在线| 成a人片国产精品| 精品制服美女久久| 亚洲综合一区二区三区| 国产精品乱子久久久久| 欧美大片日本大片免费观看| 91激情五月电影| 成人免费高清视频在线观看| 日本免费新一区视频| 一区二区三区波多野结衣在线观看| 久久中文娱乐网| 欧美一区二区三区性视频| 91成人在线观看喷潮| 不卡电影免费在线播放一区| 国产在线精品一区二区不卡了 | 成人精品一区二区三区中文字幕| 日韩av中文字幕一区二区| 亚洲一区二区在线免费观看视频| 中文字幕一区三区| 国产精品久久久久久久久免费樱桃 | 亚洲蜜臀av乱码久久精品| 国产日韩综合av| 久久综合av免费| 久久综合久久综合九色| www激情久久| 26uuu欧美日本| 精品少妇一区二区三区| 日韩免费性生活视频播放| 欧美一区二区免费视频| 在线播放视频一区| 日韩一区二区三区四区 | 蜜臀av一区二区在线免费观看 | 一区二区在线电影| 亚洲色图色小说| 亚洲精品免费在线播放| 亚洲精品日韩综合观看成人91| 国产精品国产三级国产| 国产精品福利一区二区| 自拍偷自拍亚洲精品播放| 亚洲欧洲中文日韩久久av乱码| 亚洲嫩草精品久久| 亚洲一区在线观看视频| 日日夜夜免费精品视频| 男人操女人的视频在线观看欧美| 日本亚洲免费观看| 久久99精品久久久久| 国产精品资源网| a4yy欧美一区二区三区| 91黄色免费看| 欧美一区在线视频| 2020国产精品久久精品美国| 国产精品美女久久久久久久| 樱桃国产成人精品视频| 石原莉奈一区二区三区在线观看 | 欧美大度的电影原声| 久久久精品免费免费| 亚洲人xxxx| 蜜桃视频一区二区三区在线观看| 国产一区美女在线| 成人爽a毛片一区二区免费| 91美女在线看| 91精品久久久久久久99蜜桃 | 精品一区二区三区不卡| 成人精品电影在线观看| 欧美视频中文一区二区三区在线观看| 678五月天丁香亚洲综合网| 久久久一区二区| 一区二区三区四区高清精品免费观看 | 欧美在线三级电影| 久久综合狠狠综合久久综合88| 亚洲欧美激情小说另类| 蜜臀av一区二区在线观看| www.66久久| 欧美va日韩va| 亚洲欧美国产高清| 国产在线不卡一卡二卡三卡四卡| 91色在线porny| 欧美mv日韩mv国产| 亚洲一区二三区| 成人一区二区视频| 欧美大片在线观看一区| 亚洲午夜一区二区三区| 成人av影视在线观看| 日韩免费视频线观看| 亚洲最新视频在线播放| 国产精品白丝jk白祙喷水网站| 欧美性猛交xxxx乱大交退制版| 国产亚洲一区二区在线观看| 亚洲图片欧美一区| 99久精品国产| 国产亚洲视频系列| 捆绑调教一区二区三区| 91福利在线观看| 欧美国产激情一区二区三区蜜月| 免费高清在线一区| 欧美日韩中文另类| 亚洲男人的天堂在线aⅴ视频| 国内精品免费**视频| 欧美一级理论片| 午夜激情综合网| 欧美日韩aaaaa| 午夜激情一区二区| 欧美日韩国产a| 亚洲自拍偷拍九九九| 91污在线观看| 国产精品家庭影院| 波多野结衣精品在线| 中文幕一区二区三区久久蜜桃| 久久69国产一区二区蜜臀 | 欧美私模裸体表演在线观看| 日韩美女精品在线| www.亚洲人| 亚洲婷婷综合色高清在线| 成人av第一页| 亚洲免费观看在线视频| 色综合久久久久网| 亚洲一区二区偷拍精品| 欧美精品高清视频|