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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? 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

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美少妇bbb| 日韩精品一区二区三区swag| 日韩精品一区二区三区老鸭窝| 国产一区二区三区四区五区美女| 欧美日韩在线精品一区二区三区激情| 亚洲视频狠狠干| 高清在线不卡av| 久久影视一区二区| 国产精品一区不卡| 国产精品乱码人人做人人爱| 东方欧美亚洲色图在线| 日精品一区二区三区| 欧美一区二区三区免费观看视频| 日韩精品亚洲一区| 亚洲精品一二三区| 欧美日韩国产一级二级| 日本v片在线高清不卡在线观看| 51精品视频一区二区三区| 美女精品自拍一二三四| 国产日韩欧美一区二区三区乱码| 丁香天五香天堂综合| 经典三级在线一区| 国产精品国产馆在线真实露脸| 在线观看av一区二区| 日韩国产在线观看一区| 日韩欧美一区在线观看| 成人性生交大片免费看中文| 亚洲国产精品一区二区www| 欧美一区二区三区成人| 欧美日韩另类一区| 91成人免费电影| 久久国产精品99精品国产| 亚洲图片你懂的| 中文字幕不卡一区| 欧美喷水一区二区| 欧美日本精品一区二区三区| 欧美偷拍一区二区| 欧美人xxxx| 欧美精品777| 成年人午夜久久久| 婷婷激情综合网| 亚洲欧美怡红院| 欧美精品一区视频| 欧美日韩一区不卡| 欧美精品三级日韩久久| 91麻豆精品91久久久久同性| 欧美一区二区三区婷婷月色| 91麻豆精品国产自产在线| 欧美一区二区免费观在线| 日韩三级电影网址| 久久综合精品国产一区二区三区| 久久久精品国产免费观看同学| 欧美亚洲国产一区二区三区va | 在线观看亚洲成人| 欧美午夜在线观看| 欧美一级片在线观看| 欧美成人国产一区二区| 色婷婷国产精品| 国产精品一线二线三线| 粉嫩aⅴ一区二区三区四区| 成人激情午夜影院| 在线观看亚洲a| 日韩你懂的电影在线观看| 久久久久久免费毛片精品| 国产精品电影院| 婷婷亚洲久悠悠色悠在线播放| 精品一区二区久久| 成人激情综合网站| 欧美精品丝袜久久久中文字幕| 日韩欧美视频在线| 中文字幕av一区二区三区免费看| 亚洲色图在线看| 青青草国产精品亚洲专区无| 国产成人在线色| 国产精品综合一区二区| 色综合天天综合| 国产成人精品亚洲日本在线桃色| 99国产精品一区| 高清免费成人av| 欧美日本在线一区| 国产欧美中文在线| 亚洲高清免费观看| 国产高清精品网站| 欧美日韩大陆在线| 日本一区二区三区免费乱视频| 亚洲一区日韩精品中文字幕| 综合久久一区二区三区| 奇米影视一区二区三区| 成人不卡免费av| 日韩丝袜美女视频| 亚洲卡通动漫在线| 激情综合色丁香一区二区| 国内精品免费在线观看| 欧美在线视频不卡| 国产亚洲一区二区三区四区| 欧美国产一区二区在线观看| 偷拍日韩校园综合在线| 成人中文字幕合集| 欧美一区二区三级| 一片黄亚洲嫩模| 蜜桃传媒麻豆第一区在线观看| 99久久精品国产一区二区三区| 日韩一区二区视频| 一区二区欧美国产| 99久久精品久久久久久清纯| 久久亚洲欧美国产精品乐播| 视频在线观看91| 在线观看av不卡| 成人欧美一区二区三区1314| 国产一区二区主播在线| 欧美丰满高潮xxxx喷水动漫| 亚洲欧美日韩精品久久久久| 视频在线在亚洲| 欧美伊人久久久久久午夜久久久久| 国产午夜一区二区三区| 久久黄色级2电影| 欧美一级国产精品| 午夜不卡av在线| 欧美性高清videossexo| 亚洲免费观看在线视频| 成人午夜在线免费| 中文字幕av一区二区三区免费看 | 琪琪一区二区三区| 欧美日韩一区二区三区视频| 一区二区三区 在线观看视频| 91丨porny丨国产入口| 91精品免费观看| 天堂成人国产精品一区| 欧美精品一级二级三级| 五月婷婷综合网| 欧美精品在欧美一区二区少妇| 一区二区三区四区高清精品免费观看| 不卡视频在线看| 国产精品久久久爽爽爽麻豆色哟哟| 国产精品一区二区黑丝| 亚洲国产精华液网站w| 懂色av一区二区三区蜜臀| 亚洲国产精品ⅴa在线观看| 成人av在线观| 亚洲免费观看在线视频| 欧美在线综合视频| 亚洲成av人在线观看| 成人免费看视频| 最新中文字幕一区二区三区| 99久久久免费精品国产一区二区| 国产精品高清亚洲| 一本大道久久a久久精品综合| 亚洲日本丝袜连裤袜办公室| 91九色02白丝porn| 天堂久久一区二区三区| 精品少妇一区二区三区在线播放| 国产乱码精品1区2区3区| 国产精品丝袜在线| 在线视频你懂得一区| 亚洲成人动漫精品| 精品国产免费久久| 成人免费视频一区| 一区二区三区自拍| 欧美一级高清片| 国产不卡视频在线观看| 亚洲欧美激情视频在线观看一区二区三区 | 亚洲成a人v欧美综合天堂 | 国产精品成人在线观看| 91久久精品日日躁夜夜躁欧美| 91美女片黄在线| 91啪在线观看| 欧美日韩一二三区| 亚洲成av人在线观看| 精品日韩在线一区| av在线综合网| 国产一区啦啦啦在线观看| 欧美日韩国产色站一区二区三区| 91视频com| 亚洲一区二区在线观看视频 | 久久久久久久久久久久电影 | 日韩精品三区四区| 国产情人综合久久777777| 91伊人久久大香线蕉| 人人精品人人爱| 国产精品免费网站在线观看| 欧美久久高跟鞋激| 成人夜色视频网站在线观看| 亚洲国产视频网站| 久久嫩草精品久久久精品一| 色婷婷精品久久二区二区蜜臀av | 亚洲综合在线视频| 久久蜜臀中文字幕| 色欧美乱欧美15图片| 韩国视频一区二区| 亚洲制服丝袜一区| 国产欧美日韩麻豆91| 91精品国产综合久久精品| jlzzjlzz亚洲日本少妇| 奇米综合一区二区三区精品视频| 亚洲四区在线观看| 久久亚洲一区二区三区四区| 欧美日韩在线播| 99久久免费视频.com| 精品亚洲免费视频| 婷婷开心久久网|