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

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

?? win32 multithreading and synchronization.html

?? a collection of mega hacking tools
?? HTML
?? 第 1 頁 / 共 2 頁
字號:
	<div class="center">

		<pre class="example">

DWORD WaitForMultipleObjects(

   DWORD nCount,             // number of handles in array

   CONST HANDLE *lpHandles,  // object-handle array

   BOOL bWaitAll,            // wait option

   DWORD dwMilliseconds      // time-out interval

);

</pre>

	</div>

	<p>

		If the third parameter is set to TRUE, the function will wait for all of the objects to become available. If the third parameter is set to FALSE, the function will wait for any of the objects to become available, the return value of the function will be the index to the handles array to let you know which object that has been obtained.

	</p>

	<p class="para">

		<span class="function">WaitForMultipleObjectsEx</span> is the same as <span class="function">WaitForSingleObjectEx</span>, except it allows you to wait for multiple objects.

	</p>

	<div class="center">

		<pre class="example">

DWORD WaitForMultipleObjectsEx(

  DWORD nCount,             // number of handles in array

  CONST HANDLE *lpHandles,  // object-handle array

  BOOL bWaitAll,            // wait option

  DWORD dwMilliseconds,     // time-out interval

  BOOL bAlertable           // alertable option

);

</pre>

	</div>

	<a name="mutex">

	<h3>Mutexes:</h3>

	<p class="para">

		Like all other synchronization objects, a mutex is created by the Windows Object Manager. Mutex is short for mutual exclusion, meaning that only one thread can own it at a time. Think of it as a sort of ticket, any thread holding the ticket gets to access whatever is being protected by the mutex. While the thread is doing its job, all the other threads wait. Once the thread is done, it gives the ticket away and the next thread can do what it needs to do while the other threads wait.

	</p>

	<p class="para">

		To create a mutex call <span class="function">CreateMutex</span>:

	</p>

	<div class="center">

		<pre class="example">

HANDLE CreateMutex(

   LPSECURITY_ATTRIBUTES lpMutexAttributes,

   BOOL bInitialOwner,                       // initial owner

   LPCTSTR lpName                            // object's name

);

</pre>

	</div>

	<p>

		The first parameter can be passed as NULL to obtain the default access rights. If the second parameter is set to TRUE, the creator of the mutex will have ownership first. The third parameter is optional, it can be used to easily identify the mutex.

	</p>

	<p class="para">

		To release the mutex after doing whatever needs to be done, call <span class="function">ReleaseMutex</span>.

	</p>

	<div class="center">

		<pre class="example">

BOOL ReleaseMutex(

   HANDLE hMutex   // handle to mutex

);

</pre>

	</div>

	<p>

		Only the thread that owns the mutex can release it. To destroy the mutex, call <span class="function">CloseHandle</span> with the handle to the mutex.

	</p>

	</div>

	<a name="sema">

	<h3>Semaphores:</h3>

	<p class="para">

		A semaphore is useful when you want to only allow a limited amount of threads to access a protected resource at a time. With a mutex, only one thread can own it at any given moment. With a semaphore, multiple threads can own it at a time. Consequently, any thread can also destroy the semaphore. To create a semaphore call <span class="function">CreateSemaphore</span>.

	</p>

	<div class="center">

		<pre class="example">

HANDLE CreateSemaphore(

   LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,

   LONG lInitialCount,                          // initial count

   LONG lMaximumCount,                          // maximum count

   LPCTSTR lpName                               // object's name

);

</pre>

	</div>

	<p>

		The first parameter is handled the exact same as the first parameter of <span class="function">CreateMutex</span>. The second parameter sets the initial count of the semaphore, usually it's set to the same value as that of the maximum count. The initial count cannot be less than zero nor greater than the maximum count. The third parameter sets the maximum count which limits the number of threads that can own the semaphore. The last parameter is handled the same way as that of <span class="function">CreateMutex</span>. After a thread gains possession of the semaphore the initial count is decremented one. If the initial count reaches 0, no more threads can gain possession of the semaphore. The initial count is incremented after a thread releases the semaphore.

	</p>

	<p class="para">

		To release a semaphore, call <span class="function">ReleaseSemaphore</span>.

	</p>

	<div class="center">

		<pre class="example">

BOOL ReleaseSemaphore(

   HANDLE hSemaphore,       // handle to semaphore

   LONG lReleaseCount,      // count increment amount

   LPLONG lpPreviousCount   // previous count

);

</pre>

	</div>

	<p>

		The second parameter sets by how much the count should be incremented, usually this is 1. The third parameter holds a pointer to a variable that will be filled with the previous count, after <span class="function">ReleaseSemaphore</span> completes.

	</p>

	<a name="cs">

	<h3>Critical Sections:</h3>

	<p class="para">

		A critical section is very similar to a mutex. A critical section can only be owned  by one thread at a time, however, a critical section cannot be shared between processes, a mutex can. Because of this, a critical section works more quickly. To create a critical section, call <span class="function">InitializeCriticalSection</span>; to own a critical section, call <span class="function">EnterCriticalSection</span>; to give up ownership of a critical section, call <span class="function">LeaveCriticalSection</span>; to destroy a critical section, call <span class="function">DeleteCriticalSection</span>.

	</p>

	<div class="center">

		<pre class="example">

VOID InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection);

</pre>

	</div>

	<div class="center">

		<pre class="example">

VOID EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection);

</pre>

	</div>

	<div class="center">

		<pre class="example">

VOID LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection);

</pre>

	</div>

	<div class="center">

		<pre class="example">

VOID DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection);

</pre>

	</div>

	<p>

		All of the functions require a pointer to the critical section object. You declare one like this:

	</p>

	<div class="center">

		<pre class="example">

CRITICAL_SECTION cs;

</pre>

	</div>

	<p class="para">

		Any thread that is of the process that created the critical section can destroy the critical section.

	</p>

	<a name="events">

	<h3>Events:</h3>

	<p class="para">

		An event object is useful when you want to alert threads of an action occurring, a button being pushed for example. An event object is sent to all waiting threads. Call <span class="function">CreateEvent</span> to create an event; call <span class="function">SetEvent</span> to signal an event; call <span class="function">ResetEvent</span> to turn the signal off. When an event is signaled, all threads that wait for it will receive it; when the event is not signaled, the threads will wait. You can also call <span class="function">PulseEvent</span> to quickly signal and unsignal an event. This is useful in releasing the waiting threads.

	</p>

	<p class="para">

		<span class="function">CreateEvent</span> takes the following parameters:

	</p>

	<div class="center">

		<pre class="example">

HANDLE CreateEvent(

   LPSECURITY_ATTRIBUTES lpEventAttributes,

   BOOL bManualReset,                       // reset type

   BOOL bInitialState,                      // initial state

   LPCTSTR lpName                           // object name

);

</pre>

	</div>

	<p>

		If the second parameter is set to TRUE, the event must be reset manually. If the second parameter is set to FALSE, the event will return to its unsignaled state immediately after a call to <span class="function">SetEvent</span>. If the third parameter is set to TRUE, the event will be created and set to the signaled state. The last parameter is an optional name for the object.

	</p>

	<p class="para">

		<span class="function">SetEvent</span>, <span class="function">ResetEvent</span>, and <span class="function">PulseEvent</span> are all called in the same way:

	</p>

	<div class="center">

		<pre class="example">

BOOL SetEvent(HANDLE hEvent);

</pre>

	</div>

	<div class="center">

		<pre class="example">

BOOL ResetEvent(HANDLE hEvent);

</pre>

	</div>

	<div class="center">

		<pre class="example">

BOOL PulseEvent(HANDLE hEvent);

</pre>

	</div>

	<p>

		hEvent being the handle returned from <span class="function">CreateEvent</span>.

	</p>

	<p class="para">

		The combination of a mutex and an event is a good way to avoid deadlocks. The following is an example of using the mutex and event synchronization objects.

	</p>

	<div class="center">

		<pre class="example">

#define WIN32_LEAN_AND_MEAN

#include &lt;windows.h&gt;

#include &lt;iostream&gt;



HANDLE hMutex, hWriteDone, hReadDone;

int num, state;



void Writer()

{

  for(int x=10; x>=0; x--)

  {

    while (true)

    {

      if (WaitForSingleObject(hMutex, INFINITE) == WAIT_FAILED)

      {

        std::cout<<"In writing loop, no mutex!\n";

        ExitThread(0);

      }

      if (state == 0)

      {

        ReleaseMutex(hMutex);



        WaitForSingleObject(hReadDone, INFINITE);

        continue;

      }



      break;

    }



    std::cout<<"Write done\n";

    num= x;

    state= 0;

    ReleaseMutex(hMutex);

    PulseEvent(hWriteDone);

  }

}



void Reader()

{

  while(true)

  {

    if (WaitForSingleObject(hMutex, INFINITE) == WAIT_FAILED)

    {

      std::cout<<"In reader, no mutex!\n";

      ExitThread(0);

    }

    if (state == 1)

    {

      ReleaseMutex(hMutex);



      WaitForSingleObject(hWriteDone, INFINITE);

      continue;

    }

    if (num == 0)

    {

      std::cout<<"End of data\n";

      ReleaseMutex(hMutex);

      ExitThread(0);

    }

    else {

      std::cout<<"Read done\n";

      state=1;

      ReleaseMutex(hMutex);

      PulseEvent(hReadDone);

    }

  }

}



void main()

{

  HANDLE TName[2];

  DWORD ThreadID;



  state= 1;

  

  hMutex= CreateMutex(NULL, FALSE, NULL);



  hWriteDone= CreateEvent(NULL, TRUE, FALSE, NULL);

  hReadDone= CreateEvent(NULL, TRUE, FALSE, NULL);



  TName[0]= CreateThread(NULL, 0,

    (LPTHREAD_START_ROUTINE)Writer,

    NULL, 0, &ThreadID);



  TName[1]= CreateThread(NULL, 0,

    (LPTHREAD_START_ROUTINE)Reader,

    NULL, 0, &ThreadID);



  WaitForMultipleObjects(2, TName, TRUE, INFINITE);



  CloseHandle(TName);

}

</pre>

	</div>

	<a name="ref">

	<h2>References:</h2>

	<ul>

		<li><a href="http://msdn.microsoft.com" target="_blank" title="Link opens in a new browser window.">Microsoft Developer Network</a></li>

		<li><u>Windows 98 Developer's Handbook</u> by Ben Ezzell and Jim Blaney, Sybex Publishing</li>

	</ul>

	<a name="con">

	<h2>Conclusion:</h2>

  	<p class="para">

		And so ends yet another text file. As always, if you find any errors or have any comments please send them to <a href="mailto:spiderman@witty.com" title="Click to e-mail me.">spiderman@witty.com</a>. Please direct all questions to the message board. Until next time...

	</p>

	<div class="lastupdate">Last updated: <strong>1/22/01</strong></div>

</body>

</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品剧情在线亚洲| 欧美午夜电影在线播放| 久久综合五月天婷婷伊人| 蜜臀av性久久久久蜜臀aⅴ四虎| 日韩欧美美女一区二区三区| 久久精品国产亚洲aⅴ| 久久久久久久久久久久久女国产乱| 国产电影一区二区三区| 国产精品免费丝袜| 91国偷自产一区二区使用方法| 亚洲高清一区二区三区| 日韩视频在线一区二区| 国产高清无密码一区二区三区| 中文字幕在线不卡一区| 欧美色综合网站| 精品在线观看免费| 国产精品高潮久久久久无| 欧美日韩视频一区二区| 激情伊人五月天久久综合| 欧美激情一区二区三区不卡 | 丝袜美腿亚洲一区| 欧美白人最猛性xxxxx69交| 国产精品66部| 亚洲国产一区在线观看| 精品国产伦一区二区三区观看体验| 国产成人精品三级麻豆| 亚洲国产cao| 欧美国产成人精品| 777午夜精品免费视频| 粉嫩蜜臀av国产精品网站| 亚洲成人av一区| 欧美激情一区不卡| 日韩情涩欧美日韩视频| 91美女精品福利| 国产一区二区三区在线观看免费 | 香蕉久久夜色精品国产使用方法 | 亚洲美女屁股眼交| 日韩美女一区二区三区| 91视频一区二区| 精品在线一区二区三区| 亚洲一区电影777| 亚洲va欧美va人人爽午夜| 日韩精品一区二区三区在线观看 | 国产 欧美在线| 日本亚洲最大的色成网站www| 中文字幕一区二区三区不卡在线| 精品卡一卡二卡三卡四在线| 欧美在线色视频| 成人免费电影视频| 国产最新精品精品你懂的| 亚洲国产日日夜夜| 亚洲视频在线一区二区| 久久综合九色综合97婷婷女人| 在线观看www91| 色综合欧美在线视频区| 国产成人免费xxxxxxxx| 美女脱光内衣内裤视频久久影院| 亚洲免费电影在线| 国产精品美女www爽爽爽| 国产亚洲制服色| 欧美精品一区视频| 欧美α欧美αv大片| 日韩一级二级三级精品视频| 欧美亚洲高清一区| 91久久国产最好的精华液| 成人综合在线观看| 国产乱子伦一区二区三区国色天香| 奇米影视在线99精品| 日韩精品国产精品| 石原莉奈在线亚洲三区| 午夜国产精品影院在线观看| 亚洲第一在线综合网站| 亚洲男人电影天堂| 亚洲一区视频在线观看视频| 亚洲综合成人网| 亚洲va天堂va国产va久| 五月激情综合婷婷| 日韩成人伦理电影在线观看| 日韩国产欧美在线播放| 日本不卡视频在线观看| 蜜臀99久久精品久久久久久软件 | 亚洲国产aⅴ成人精品无吗| 亚洲香蕉伊在人在线观| 性欧美大战久久久久久久久| 午夜精品久久久久久久99樱桃| 视频一区在线播放| 免费久久精品视频| 精品影视av免费| 成人综合激情网| 97超碰欧美中文字幕| 在线观看91视频| 91精品国产综合久久福利软件| 欧美成人伊人久久综合网| 久久久精品影视| 国产精品电影一区二区| 一区二区三区在线观看欧美| 午夜精品一区二区三区三上悠亚| 欧美aaa在线| 国产精品 日产精品 欧美精品| 国产成人久久精品77777最新版本| 国产91精品免费| 欧美午夜精品一区二区蜜桃| 欧美一级一级性生活免费录像| 国产亚洲精品中文字幕| 亚洲精品中文在线影院| 日av在线不卡| 懂色av噜噜一区二区三区av | 欧美日韩视频不卡| 日韩欧美在线网站| 国产精品嫩草影院com| 亚洲va欧美va人人爽| 国产一区二区在线免费观看| 99麻豆久久久国产精品免费| 亚洲国产精品国自产拍av| 亚洲国产综合人成综合网站| 精品制服美女丁香| 欧洲一区在线电影| 久久麻豆一区二区| 一级日本不卡的影视| 国产综合一区二区| 欧美偷拍一区二区| 国产亚洲精品福利| 日韩高清在线电影| av在线不卡电影| 精品久久久久香蕉网| 玉米视频成人免费看| 精品一区二区三区日韩| 日本高清不卡一区| 国产日韩影视精品| 天天色 色综合| 91蜜桃婷婷狠狠久久综合9色| 日韩精品一区二区三区蜜臀| 亚洲激情av在线| 丰满少妇在线播放bd日韩电影| 91精品国产色综合久久不卡电影 | 亚洲午夜av在线| 丁香另类激情小说| 日韩午夜三级在线| 亚洲综合免费观看高清完整版| 国产精品88888| 日韩一区二区不卡| 午夜视频在线观看一区二区三区| 99久久99久久综合| 久久综合九色欧美综合狠狠| 天天操天天干天天综合网| 欧美专区日韩专区| 成人免费在线观看入口| 国产精品中文字幕日韩精品 | 久久久精品中文字幕麻豆发布| 午夜久久久久久久久| 在线视频国内自拍亚洲视频| 1区2区3区国产精品| 国产 日韩 欧美大片| xf在线a精品一区二区视频网站| 天堂av在线一区| 欧美日韩高清在线| 亚洲一区中文在线| 在线视频你懂得一区| 亚洲另类春色校园小说| av成人动漫在线观看| 国产精品久久久久aaaa| 丁香啪啪综合成人亚洲小说| 亚洲国产精品国自产拍av| 国产99久久久久久免费看农村| 一区二区三区欧美激情| 成人av先锋影音| 中文字幕在线一区| 91在线精品一区二区| 中文字幕在线免费不卡| 99久久精品免费| 亚洲精品视频在线看| 一本大道久久a久久综合| 樱花草国产18久久久久| 欧洲国内综合视频| 丝袜诱惑制服诱惑色一区在线观看 | 成人久久18免费网站麻豆| 国产女人水真多18毛片18精品视频| 国产精品一级在线| 国产精品黄色在线观看| 91亚洲精品乱码久久久久久蜜桃| 一区二区在线观看视频在线观看| 欧洲在线/亚洲| 美国三级日本三级久久99| 欧美精品一区二区三区在线 | 欧美精品vⅰdeose4hd| 天天综合天天做天天综合| 精品久久久久久久人人人人传媒| 国产一区二区网址| 亚洲国产高清不卡| 91激情在线视频| 日本不卡免费在线视频| 久久久亚洲综合| 91片在线免费观看| 婷婷成人激情在线网| 精品国产凹凸成av人网站| av电影天堂一区二区在线| 午夜视频一区在线观看| 亚洲va韩国va欧美va精品| 精品国产人成亚洲区| 成人99免费视频|