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

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

?? active.html

?? windows系統編程 一本很好的書!值得看哦!
?? HTML
字號:
<html>
<head>
<title>Active Objects</title>
<meta  name="description" content="Reliable software Win32 Tutorial: Threads">
<meta name="keywords" content="reliable, software, windows, cplusplus, source code, example, tutorial, thread, multitasking, synchronization, critical section, semaphore, event, threads, object oriented">
</head>

<body background="../images/grid.gif" bgcolor="white" text="black">
<script language="JAVASCRIPT">
<!--
if (navigator.onLine){
document.write("<!-- Spidersoft WebZIP Ad Banner Insert -->");
document.write("<TABLE width=100% border=0 cellpadding=0 cellspacing=0>");
document.write("<TR>");
document.write("<TD>");
document.write("<ILAYER id=ad1 visibility=hidden height=60></ILAYER>");
document.write("<NOLAYER>");
document.write("<IFRAME SRC='http://www.spidersoft.com/ads/bwz468_60.htm' width=100% height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></IFRAME>");
document.write("</NOLAYER>");
document.write("</TD>");
document.write("</TR>");
document.write("</TABLE>");
document.write("<!-- End of Spidersoft WebZIP Ad Banner Insert-->");
}
 //-->
</script>


<table cellpadding=10 width="100%">
<tr>
   <td width=100 align=center valign=middle>
      <a href="../index.htm">
      <img src="../images/rsbullet.gif" alt="RS" border=0 width=39 height=39>
      <br>Home</a>
   <td><font face="arial" color="#009966">
       <h1 align=center>Using Threads</h1>
       </font>
</table>


<p>
<table width="100%">
<tr>
   <td width=80> <!-- Left margin -->
   <td> <!-- Middle column, there is also the right margin at the end -->

   <table cellpadding=10 cellspacing=0 width="100%">
   <tr>
   <td bgcolor="#ffffff">


<hr>
<font size="+1"><b>Multitasking is one of the most difficult</b></font> aspects of programming. It makes it even more important to provide a simple set of abstractions and to encapsulate it in a nice object-oriented shell. In the OO world, the natural counterpart of the thread (which is a strictly procedural abstraction) is the <b>Active Object</b>. An active object owns a captive thread that performs certain tasks asynchronously. This thread has access to all the internal (private) data and methods of the object. The public interface of the Active Object is available to external agents (e.g., to the main thread, or to the Windows thread carrying messages) so that they, too, can manipulate the state of the object and that of the captive thread, albeit in a very controlled and restricted manner.
<p>An Active Object is built upon a framework called <b>ActiveObject</b>. The implementor of the derived class is supposed to provide the implementation for the pure virtual methods <i>InitThread</i>, <i>Run</i> and <i>Flush</i> (as well as write the destructor).
<hr>

<pre><font face="courier">class <font color="#cc0066"><b>ActiveObject</b></font>
{
public:
    ActiveObject ();
    virtual ~ActiveObject () {}
    void Kill ();

protected:
    virtual void InitThread () = 0;
    virtual void Run () = 0;
    virtual void FlushThread () = 0;

    static DWORD WINAPI ThreadEntry (void *pArg);

    int             _isDying;
    Thread          _thread;
};


</font></pre>
<hr>
The constructor of the ActiveObject initializes the captive thread by passing it a pointer to a function to be executed and a pointer to "this." We have to disable the warning about using "this" before it is fully constructed. We know that it won't be used too early, because the thread is created in the inactive state. The constructor of the derived class is supposed to call <i>_thread.Resume ()</i> in order to activate it.
<hr>
<pre><font face="courier"><font color="#cc0066">// The constructor of the derived class
// should call
//    _thread.Resume ();
// at the end of construction</font>

<font color="#cc0066"><b>ActiveObject::ActiveObject</b></font> ()
: _isDying (0),
#pragma warning(disable: 4355) <font color="#cc0066">// 'this' used before initialized</font>
  _thread (ThreadEntry, this)
#pragma warning(default: 4355)
{
}

</font></pre>
<hr>
The method <i>Kill</i> calls the virtual method <i>FlushThread</i> -- it is supposed to release the thread from any wait state and let it run ahead to check the <i>_isDying</i> flag.
<hr>
<pre><font face="courier">void <font color="#cc0066"><b>ActiveObject::Kill</b></font> ()
{
    _isDying++;
    FlushThread ();
    <font color="#cc0066">// Let's make sure it's gone</font>
    _thread.WaitForDeath ();
}

</font></pre>
<hr>
We also have a framework for the <i>ThreadEntry</i> function (it's a static method of ActiveObject, so we can specify the calling convention required by the API). This function is executed by the captive thread. The argument it gets from the system is the one we passed to the constructor of the thread object-- the "this" pointer of the Active Object. The API expects a void pointer, so we have to do an explicit cast to the ActiveObject pointer. Once we get hold of the Active Object, we call its pure virtual method InitThread, to make all the implementation specific preparations, and then call the main worker method, <i>Run</i>. The implementation of <i>Run</i> is left to the client of the framework.
<hr>
<pre><font face="courier">DWORD WINAPI <font color="#cc0066"><b>ActiveObject::ThreadEntry</b></font> (void* pArg)
{
    ActiveObject * pActive = (ActiveObject *) pArg;
    pActive-&gt;InitThread ();
    pActive-&gt;Run ();
    return 0;
}

</font></pre>
<hr>
The Thread object is a thin encapsulation of the API. Notice the flag <b>CREATE_SUSPENDED</b> which assures that the thread doesn't start executing before we are done with the construction of the <i>ActiveObject</i>.
<hr>

<pre><font face="courier">class <font color="#cc0066"><b>Thread</b></font>
{
public:
    Thread ( DWORD (WINAPI * pFun) (void* arg), void* pArg)
    {
        _handle = <font color="#000099"><b>CreateThread</b></font> (
            0, <font color="#cc0066">// Security attributes</font>
            0, <font color="#cc0066">// Stack size</font>
            pFun,
            pArg,
            CREATE_SUSPENDED,
            &amp;_tid);
    }
    ~Thread () { <font color="#000099"><b>CloseHandle</b></font> (_handle); }
    void Resume () { <font color="#000099"><b>ResumeThread</b></font> (_handle); }
    void WaitForDeath ()
    {
        <font color="#000099"><b>WaitForSingleObject</b></font> (_handle, 2000);
    }
private:
    HANDLE _handle;
    DWORD  _tid;     <font color="#cc0066">// thread id</font>
};

</font></pre>
<hr>
<font size="+1"><b>Synchronization is what really makes</b></font> multitasking so hard. Let's start with mutual exclusion. Class <i>Mutex</i> is a thin encapsulation of the API. You embed Mutexes in your Active Object and then use them through Locks. A <i>Lock</i> is a clever object that you construct on the stack and for the duration of its lifetime your object is protected from any other threads. Class Lock is one of the applications of the <a href="../resource/index.htm">Resource Management</a> methodology. You have to put <i>Locks</i> inside all the methods of your Active Object that access data shared with the captive thread.
<hr>
<pre><font face="courier">class <font color="#cc0066"><b>Mutex</b></font>
{
    friend class <font color="#cc0066"><b>Lock</b></font>;
public:
    Mutex () { InitializeCriticalSection (&amp; _critSection); }
    ~Mutex () { DeleteCriticalSection (&amp; _critSection); }
private:
    void Acquire ()
    {
        <font color="#000099"><b>EnterCriticalSection</b></font> (&amp; _critSection);
    }
    void Release ()
    {
        <font color="#000099"><b>LeaveCriticalSection</b></font> (&amp; _critSection);
    }

    CRITICAL_SECTION _critSection;
};

class <font color="#cc0066"><b>Lock</b></font>
{
public:
    <font color="#cc0066">// Acquire the state of the semaphore</font>
    Lock ( Mutex &amp; mutex )
        : _mutex(mutex)
    {
        _mutex.Acquire();
    }
    <font color="#cc0066">// Release the state of the semaphore</font>
    ~Lock ()
    {
        _mutex.Release();
    }
private:
    Mutex &amp; _mutex;
};
</font></pre>

<hr>
An <i>Event</i> is a signalling device that threads use to communicate with each other. You embed an <i>Event</i> in your active object. Then you make the captive thread wait on it until some other thread releases it. Remember however that if your captive thread waits on a event it can't be terminated. That's why you should call <i>Release</i> from the <i>Flush</i> method.
<hr>

<pre><font face="courier">class <font color="#cc0066"><b>Event</b></font>
{
public:
    Event ()
    {
        // start in non-signaled state (red light)
        // auto reset after every Wait
        _handle = <font color="#000099"><b>CreateEvent</b></font> (0, FALSE, FALSE, 0);
    }

    ~Event ()
    {
        <font color="#000099"><b>CloseHandle</b></font> (_handle);
    }

    // put into signaled state
    void Release () { <font color="#000099"><b>SetEvent</b></font> (_handle); }
    void Wait ()
    {
        // Wait until event is in signaled (green) state
        <font color="#000099"><b>WaitForSingleObject</b></font> (_handle, INFINITE);
    }
    operator HANDLE () { return _handle; }
private:
    HANDLE _handle;
};
</font></pre>
<hr>
To see how these classes can be put to use, I suggest a little side trip. You can jump to the page that explains how the  <a href="../recorder.html">Frequency Analyzer</a> uses the ActiveObject class to update the display asynchronously. Or, you can study a somehow simpler example of a <a href="watcher.html">Folder Watcher</a> that waits quietly watching a folder and wakes up only when a change happens.
<p>I wish I could say programming with threads was simple. It is, however, simpler if you use the right kind of primitives. The primitives I advertised here are <i>ActiveObject, Thread, Mutex, Lock</i> and <i>Event</i>. Some of them are actually available in MFC. For instance, they have a Lock object (or is it CLock?) whose destructor releases the critical section (theirs is slightly less convenient because of the "two-step" construction-- you have to create it and then take it in two separate steps-- as if you'd want to create it and then <i>not</i> take it). Other than that, MFC only offers some thin veneer over the API, nothing exciting.
<p>You might also recognize some of the mechanisms I presented here in the <b>Java</b> programming language. Of course, when you have the liberty of designing multitasking into the language, you can afford to be elegant. Their version of <i>ActiveObject</i> is called <i>Runnable</i> and it has the <i>run</i> method. Every Java object potentially has a built-in mutex and all you have to do to take a lock is to declare a method (or a scope) <i>synchronized</i>. Similarly, the events are implemented with the <i>wait</i> and <i>notify</i> calls inside any <i>synchronized</i> method. So, if you know how to program in Java, you know how to program in C++ (as if there were people fluent in Java, but ignorant of C++).
<hr>
   </table>
   <td width=60>
</table>



<layer src="http://www.spidersoft.com/ads/bwz468_60.htm" visibility=hidden id=a1 width=600 onload="moveToAbsolute(ad1.pageX,ad1.pageY); a1.clip.height=60;visibility='show';"></layer>
</body>
</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美影视一区在线| 欧美日韩国产一区| 激情综合色播激情啊| 日韩国产欧美在线播放| 亚洲图片一区二区| 亚洲国产裸拍裸体视频在线观看乱了| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 精品国产髙清在线看国产毛片| 欧美理论在线播放| 91精品国产色综合久久不卡电影| 91精品国产综合久久久久久漫画 | 亚洲午夜电影在线观看| 亚洲伊人伊色伊影伊综合网| 一区二区高清视频在线观看| 亚洲影院理伦片| 秋霞午夜鲁丝一区二区老狼| 另类调教123区| 大胆欧美人体老妇| 色呦呦一区二区三区| 欧美日韩高清一区二区不卡| 日韩女优制服丝袜电影| 国产精品午夜电影| 亚洲尤物在线视频观看| 久久国产综合精品| 99国产精品99久久久久久| 欧美人妖巨大在线| 2021中文字幕一区亚洲| 亚洲欧美综合在线精品| 日韩专区欧美专区| 国产成人在线影院| 欧美欧美欧美欧美首页| 国产亚洲短视频| 亚洲成av人影院| 国产91精品久久久久久久网曝门| 色综合久久久久| 91精品国产综合久久香蕉麻豆 | 亚洲婷婷国产精品电影人久久| 午夜国产精品影院在线观看| 国产露脸91国语对白| 色呦呦日韩精品| 亚洲精品一区在线观看| 亚洲黄色av一区| 国产一区二区三区四| 91成人在线免费观看| 国产亚洲精品福利| 蜜臀a∨国产成人精品| 色综合天天综合在线视频| 精品美女在线播放| 亚洲综合激情小说| 成人午夜在线视频| 精品成人在线观看| 天堂一区二区在线| 在线观看免费成人| 国产精品看片你懂得| 国产一区在线观看视频| 欧美高清精品3d| 一区二区三区四区亚洲| 成人黄色一级视频| 久久精品亚洲精品国产欧美 | 国产美女在线观看一区| 日韩欧美专区在线| 日日夜夜精品视频天天综合网| 99精品国产热久久91蜜凸| 国产片一区二区三区| 精品亚洲国内自在自线福利| 欧美精选在线播放| 亚洲.国产.中文慕字在线| 99re8在线精品视频免费播放| 日本一区二区免费在线观看视频| 久久精品久久久精品美女| 欧美一区二区视频网站| 欧美aaaaaa午夜精品| 欧美男同性恋视频网站| 五月天欧美精品| 欧美一区二区私人影院日本| 午夜欧美一区二区三区在线播放| 在线观看日韩毛片| 一卡二卡欧美日韩| 欧美性猛交xxxx乱大交退制版| 一区二区三区日韩欧美| 在线观看日韩av先锋影音电影院| 亚洲精选免费视频| 欧美性高清videossexo| 香蕉成人伊视频在线观看| 欧美精品一二三| 国产自产v一区二区三区c| 久久久久免费观看| 99久久伊人精品| 亚洲精品菠萝久久久久久久| 欧美日韩国产一级二级| 蜜臀久久99精品久久久久久9| 精品免费一区二区三区| 成人免费视频一区| 亚洲一区二区三区四区在线| 制服.丝袜.亚洲.另类.中文| 狠狠色丁香久久婷婷综合丁香| 欧美国产精品专区| 欧美系列在线观看| 蜜臀av一级做a爰片久久| 久久久综合视频| 色偷偷久久人人79超碰人人澡| 视频精品一区二区| 国产欧美日韩在线观看| 欧美无乱码久久久免费午夜一区| 日韩精品一区第一页| 国产欧美一区二区三区在线老狼| 一本色道久久综合狠狠躁的推荐| 日韩不卡一区二区三区| 亚洲国产精品国自产拍av| 欧美在线观看视频一区二区| 免费成人在线观看| 亚洲人亚洲人成电影网站色| 制服.丝袜.亚洲.另类.中文| 国产成人一区二区精品非洲| 亚洲一区二区3| 国产日韩欧美激情| 69av一区二区三区| eeuss鲁一区二区三区| 日本亚洲最大的色成网站www| 久久久99免费| 欧美日韩国产小视频| 成熟亚洲日本毛茸茸凸凹| 美国一区二区三区在线播放| 亚洲欧美在线另类| 久久亚洲一区二区三区四区| 欧美日韩一区二区不卡| eeuss影院一区二区三区| 国产在线一区观看| 日本视频中文字幕一区二区三区| 国产精品卡一卡二| 久久久久国产精品麻豆ai换脸| 欧美日韩国产系列| 91福利资源站| 96av麻豆蜜桃一区二区| 粉嫩在线一区二区三区视频| 免费成人美女在线观看.| 亚洲午夜免费电影| 丝袜美腿亚洲色图| 亚洲一区二区三区激情| 日韩一区在线免费观看| 国产日产欧美一区| 久久精品视频在线看| 欧美精品一区二区三区视频| 欧美一区日韩一区| 欧美日本精品一区二区三区| 在线精品视频免费播放| 91色综合久久久久婷婷| 97国产精品videossex| 99久久精品国产观看| aaa亚洲精品| 91尤物视频在线观看| 色综合天天综合网国产成人综合天 | 国产精品嫩草影院av蜜臀| 日韩一区二区精品在线观看| 在线不卡中文字幕| 9191成人精品久久| 欧美日产国产精品| 日韩精品专区在线影院观看 | 国产成人精品影院| 成人网在线免费视频| www.在线欧美| 91久久人澡人人添人人爽欧美| 欧美这里有精品| 91精品国产综合久久福利| 欧美一区二区视频观看视频| 日韩精品一区二区三区在线播放| 日韩精品专区在线| 中文成人综合网| 亚洲综合精品久久| 久久黄色级2电影| 成人精品高清在线| 欧美日韩一二三| 精品久久国产字幕高潮| 国产精品麻豆久久久| 亚洲自拍偷拍图区| 捆绑变态av一区二区三区| 国产91精品露脸国语对白| 色婷婷精品久久二区二区蜜臂av | 精品国产精品一区二区夜夜嗨 | 91日韩一区二区三区| 欧美人xxxx| 国产亚洲美州欧州综合国| 亚洲精品免费在线播放| 日韩高清电影一区| 在线亚洲+欧美+日本专区| 日韩女优视频免费观看| 国产精品免费网站在线观看| 香蕉加勒比综合久久| 国产精品综合一区二区三区| 色婷婷国产精品综合在线观看| 日韩天堂在线观看| 亚洲欧洲精品一区二区三区| 奇米777欧美一区二区| 成人免费视频视频在线观看免费| 欧美日韩一区小说| 国产精品欧美久久久久无广告| 亚洲成av人片一区二区三区| 国产91富婆露脸刺激对白| 91精品一区二区三区在线观看| 1000部国产精品成人观看|