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

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

?? win32 multithreading and synchronization.html

?? a collection of mega hacking tools
?? HTML
?? 第 1 頁 / 共 2 頁
字號(hào):
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

	<title>Win32 Multithreading and Synchronization (ver. 1.0.0)</title>

	

	<meta http-equiv="Content-Type" content="text/html charset=utf-8" />

	<meta content="Copyright 2002 SpiderMan" name="Copyright" />

	<meta content="SpiderMan" name="Author" />

	<meta content="English" name="Language" />

	

	<style type="text/css">

	<!--

		body {font: 12px Verdana, Arial, Helvetica, sans-serif}



		p {text-align: left;}

		p.para {text-indent: 12px}



		table.example {width: 450px; font-size: 12px}



		span.function {color: gray; font-weight: bold}

		span.term {color: gray; font-style: italic}

		

		div.lastupdate {text-align: right}

		/* hack so IE will center my stuff since it doesn't recognize margin: auto */

		div.center {text-align: center}

	

		a:link {text-decoration: underline; color: #003F7F}

		a:visited {text-decoration: underline; color: #003F7F}

		a:hover {text-decoration: underline; color: #CC0000}



		h2, h3 {font-size: 12px}

		h1.title {font-weight: normal; text-align: center; font-size: 12px}



		pre.example {background-color: #EBEBEB; border: 1px solid #000000; padding: 3px; text-align: left; width: 570px; margin-left: auto; margin-right: auto}

	-->

	</style>

</head>



<body>

	<h1 class="title">

		<strong>Win32 Multithreading and Synchronization (ver. 1.0.0)</strong>

		<br/>

by: <a href="mailto:spiderman@witty.com">SpiderMan</A> of <a href="http://blacksun.box.sk">Black Sun Research Facility </a>

		

	</h1>

	<h2>Table of Contents:</h2>

	<ul>

		<li><a href="#intro" title="Click to skip down to this section.">Introduction</a></li>

		<li><a href="#background" title="Click to skip down to this section.">Background</a></li>

		<li><a href="#multi" title="Click to skip down to this section.">Multithreading</a></li>

		<li><a href="#synch" title="Click to skip down to this section.">Synchronization</a></li>

		<ul>

			<li><a href="#mutex" title="Click to skip down to this section.">Mutexes</a></li>

			<li><a href="#sema" title="Click to skip down to this section.">Semaphores</a></li>

			<li><a href="#cs" title="Click to skip down to this section.">Critical Sections</a></li>

			<li><a href="#events" title="Click to skip down to this section.">Events</a></li>

		</ul>

		<li><a href="#ref" title="Click to skip down to this section.">References</a></li>

		<li><a href="#con" title="Click to skip down to this section.">Conclusion</a></li>

	</ul>

	<a name="intro">

	<h2>Introduction:</h2>

  	<p class="para">

		This tutorial will explain how to create and manage multiple threads in Windows. This is an advanced tutorial; the reader should be familiar with Win32 programming.

	</p>

	<p class="para">

		The need for responsive user-centric programs is a good reason to create programs that use multiple threads. By creating multiple threads, a program can seem to do many things at once (on a computer with more than one CPU, the program actually will do many things at once). For example, a word processor could have one thread that handles the painting of the processor's window while another thread saves the document being typed every few minutes while yet another thread actively monitors the document for spelling errors all without forcing the user to wait while each task is completed.

	</p>

	<a name="background">

	<h2>Background:</h2>

  	<p class="para">

		On a single CPU Windows machine, all threads are kept track of and given a slice of processor time (usually a few milliseconds). Windows will cycle through the list it keeps, pausing and resuming each thread. Once a thread has used up its time on the processor, Windows will pause the thread, record its CPU registers (along with some other data), and, after restoring all its data, activate the next thread. Each thread has two priorities: base and dynamic. The base priority can be changed, however, it cannot be changed to have a priority higher than that of the parent thread. Dynamic priority is the same as the base priority, however, it can be raised or lowered by Windows. Windows chooses which thread to run next based on the thread's dynamic priority. Naturally, threads with a higher dynamic priority run first.

	</p>

	<a name="multi">

	<h2>Multithreading:</h2>

	  <p class="para">

		Initially, every program gets one thread, known as the primary thread, which is created by the Windows Object Manager. The primary thread can be used to create child threads. To create another thread call <span class="function">CreateThread</span>. <span class="function">CreateThread</span> takes the following parameters:

	</p>

	<div class="center">

		<pre class="example">

HANDLE CreateThread(

   LPSECURITY_ATTRIBUTES lpThreadAttributes, // access privileges

   DWORD dwStackSize,                        // initial stack size

   LPTHREAD_START_ROUTINE lpStartAddress,    // thread function

   LPVOID lpParameter,                       // thread argument

   DWORD dwCreationFlags,                    // creation option

   LPDWORD lpThreadId                        // thread identifier

);

</pre>

	</div>

	<p>

		If the first parameter is passed as NULL, the thread will get the default security descriptor. The second parameter allows you to set the initial stack size, you can pass 0 to give the thread the default stack size. The third parameter is a pointer to the function the thread should start executing. The fourth parameter holds any arguments you want to pass to the function. You can pass either a 0 or CREATE_SUSPENDED to the fifth parameter. If it is 0, the thread starts running as soon as it is created. If the value is CREATE_SUSPENDED, the thread will be created suspended and will not start running until you call <span class="function">ResumeThread</span>. The last parameter is a pointer to a DWORD which will hold the unique ID of the thread, after it is created.

	</p>

	<p class="para">

		If a thread was created with the CREATE_SUSPENDED flag, you will want to call <span class="function">ResumeThread</span> to start using it. <span class="function">ResumeThread</span> takes the following parameter:

	</p>

	<div class="center">

		<pre class="example">

DWORD ResumeThread(HANDLE hThread);

</pre>

	</div>

	<p>

		hThread is the handle received by <span class="function">CreateThread</span>. To suspend the thread again, call <span class="function">SuspendThread</span>:

	</p>

	<div class="center">

		<pre class="example">

DWORD SuspendThread(HANDLE hThread);

</pre>

	</div>

	<p>

		Once again, hThread is the handle received by <span class="function">CreateThread</span>.

	</p>

	<p class="para">

		While a thread is suspended, you may want to raise its base priority and then wake it again. A thread with a higher priority will get more processor time. To change a thread's base priority, call <span class="function">SetThreadPriority</span>:

	</p>

	<div class="center">

		<pre class="example">

BOOL SetThreadPriority(

   HANDLE hThread, // handle to the thread

   int nPriority   // thread priority level

);

</pre>

	</div>

	<p>

		nPriority can be one of seven values:

	</p>

	<div class="center">

		<table class="example" border="1" cellspacing="0" cellpadding="2" summary="Table of possible values for thread priorities">

			<tr>

				<td>THREAD_PRIORITY_LOWEST</td>

				<td>Two levels below process</td>

			</tr>

			<tr>

				<td>THREAD_PRIORITY_BELOW_NORMAL</td>

				<td>One level below process</td>

			</tr>

			<tr>

				<td>THREAD_PRIORITY_NORMAL</td>

				<td>Normal priority</td>

			</tr>

			<tr>

				<td>THREAD_PRIORITY_ABOVE_NORMAL</td>

				<td>One level above process</td>

			</tr>

			<tr>

				<td>THREAD_PRIORITY_HIGHEST</td>

				<td>Two levels above process</td>

			</tr>

			<tr>

				<td>THREAD_PRIORITY_TIME_CRITICAL</td>

				<td>Priority of 15</td>

			</tr>

			<tr>

				<td>THREAD_PRIORITY_IDLE</td>

				<td>Priority of 1</td>

			</tr>

		</table>

	</div>

	<p>

		To retrieve a thread's base priority level, call <span class="function">GetThreadPriority</span>:

	</p>

	<div class="center">

		<pre class="example">

int GetThreadPriority(HANDLE hThread);

</pre>

	</div>

	<p class="para">

		After you are done using a thread, you may want to terminate it. To do this, call <span class="function">ExitThread</span>. <span class="function">ExitThread</span> followed by a <span class="function">CloseHandle</span> is the graceful way to shut down a thread. To immediately stop a thread, call <span class="function">TerminateThread</span>. The specs of each function are:

	</p>

	<div class="center">

		<pre class="example">

VOID ExitThread( DWORD dwExitCode);

</pre>

	</div>

	<div class="center">

		<pre class="example">

BOOL CloseHandle(HANDLE hThread);

</pre>

	</div>

	<div class="center">

		<pre class="example">

BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode);

</pre>

	</div>

	<p>

		Windows automatically calls <span class="function">ExitThread</span> when a thread ends its function. dwExitCode is the exit code you want to pass. The exit code can later be retrieved using <span class="function">GetExitCodeThread</span>:

	</p>

	<div class="center">

		<pre class="example">

BOOL GetExitCodeThread(

   HANDLE hThread,

   LPDWORD lpExitCode   // pointer to a DWORD to hold the exit code

);

</pre>

	</div>

	<p class="para">

		The following is an example of how to use threads.

	</p>

	<div class="center">

		<pre class="example">

#define WIN32_LEAN_AND_MEAN

#include &lt;windows.h&gt;

#include &lt;iostream&gt;



DWORD ThreadID;

HANDLE TName;



void ExampleFunction()

{

  for(int x=0; x<10; x++)

  {

    std:cout<<"Doing important stuff!\n";

  }

}



void main()

{

  TName= CreateThread(NULL, 0,

    (LPTHREAD_START_ROUTINE)ExampleFunction,

    NULL, CREATE_SUSPENDED, &ThreadID);



  if (TName == NULL)

  {

    std::cout<<"Could not create thread!\n";

    return false;

  }

			

  if (!SetThreadPriority(TName, THREAD_PRIORITY_BELOW_NORMAL))

  {

    std::cout<<"SetThreadPriority failed!\n";

    return false;

  }



  if ((ResumeThread(TName)) == -1)

  {

    std::cout<<"ResumeThread failed!\n";

    return false;

  }

  

  WaitForSingleObject(TName, INFINITE);  // discussed later



  CloseHandle(TName);

}

</pre>

	</div>

	<a name="synch">

	<h2>Synchronization:</h2>

	<p class="para">

		Picture this: a word processor program creates two threads, one to read a file and another to write to a file. Everything is fine at first, the first thread waits for the second to finish writing to the file before reading it. The two threads work happily, everything is fine as long as the writing thread always writes first. But one dark day, the reading thread reads the file before the writing thread writes to the file and the program fails. This is known as a <span class="term">race condition</span> because both threads race to finish their file operation. The program will always fail if the reading thread wins the race. A <span class="term">race condition</span> is the result of bad synchronization. Another problem is the dreaded <span class="term">deadlock</span>. In a <span class="term">deadlock</span>, both threads will wait for each other to finish but neither thread will finish until the other finishes first, causing them to become locked. The solution to this problem is to use one, or more, of the synchronization objects provided by Windows.

	</p>

	<p class="para">

		To gain ownership of any of the synchronization objects, a thread can use <span class="function">WaitForSingleObject</span>, <span class="function">WaitForSingleObjectEx</span>, <span class="function">WaitForMultipleObjects</span>, or <span class="function">WaitForMultipleObjectsEx</span>.

	</p>

	<p class="para">

		<span class="function">WaitForSingleObject</span> allows a thread to suspend itself while it waits for ownership of one of the synchronization objects.

	</p>

	<div class="center">

		<pre class="example">

DWORD WaitForSingleObject(

   HANDLE hHandle,        // handle to object

   DWORD dwMilliseconds   // time-out interval

);

</pre>

	</div>

	<p>

		The second parameter is the amount of time, in milliseconds, the thread is willing to wait for the object before it returns. If the second parameter is set to INFINITE, the function will not time-out. If the second parameter is set to 0, the function will try to gain ownership of the object and return immediately, even if it didn't gain ownership.

	</p>

	<p class="para">

		<span class="function">WaitForSingleObjectEx</span> is the same as <span class="function">WaitForSingleObject</span> except, it adds one more option: alert if I/O operation completes.

	</p>

	<div class="center">

		<pre class="example">

DWORD WaitForSingleObjectEx(

   HANDLE hHandle,        // handle to object

   DWORD dwMilliseconds,  // time-out interval

   BOOL bAlertable        // alertable option

);

</pre>

	</div>

	<p>

		If the last parameter is set to true, the function will return when an asynchronous I/O operation completes.

	</p>

	<p class="para">

		<span class="function">WaitForMultipleObjects</span> allows a thread to wait for multiple synchronization objects at once. It can be set to return when any or all of the objects become available.

	</p>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色美美综合视频| 国产一区三区三区| 在线观看欧美精品| 亚洲国产成人av网| 欧美肥妇free| 久久99久久久久| 久久久久国产一区二区三区四区| 国产剧情av麻豆香蕉精品| 国产欧美精品一区二区色综合| 丁香六月综合激情| 亚洲精品中文字幕在线观看| 欧美日韩视频第一区| 久久国内精品自在自线400部| 国产三级一区二区| 色诱视频网站一区| 日韩国产欧美三级| 久久久久久久久99精品| 色婷婷精品久久二区二区蜜臀av| 日韩二区三区四区| 国产日韩欧美一区二区三区乱码| 一本久久精品一区二区| 日韩精品乱码av一区二区| 久久久久久麻豆| 欧美色男人天堂| 经典三级一区二区| 一区二区三区四区五区视频在线观看| 欧美色图激情小说| 夫妻av一区二区| 日本欧美加勒比视频| 国产人成亚洲第一网站在线播放 | 国产欧美va欧美不卡在线| heyzo一本久久综合| 免费日韩伦理电影| 亚洲欧美偷拍卡通变态| 精品国产sm最大网站免费看| 91麻豆精品在线观看| 久久精品国产精品亚洲红杏| 亚洲精品国产第一综合99久久 | 一区二区成人在线| 久久精品水蜜桃av综合天堂| 欧美性生活久久| 不卡一区中文字幕| 九九国产精品视频| 亚洲国产一区二区在线播放| 国产精品乱码一区二区三区软件 | 午夜激情一区二区| 国产精品久久久久久久裸模| 日韩一区二区三区免费观看| 欧美性猛交xxxxxxxx| 粗大黑人巨茎大战欧美成人| 麻豆精品一区二区av白丝在线| 亚洲久草在线视频| 国产精品久久久久婷婷| 久久精品一二三| 精品粉嫩aⅴ一区二区三区四区| 91久久免费观看| 成年人网站91| 成人手机电影网| 国产精品一区二区在线播放 | 国产欧美一二三区| 精品电影一区二区三区| 日韩欧美国产综合在线一区二区三区| 日本大香伊一区二区三区| 91原创在线视频| 91蝌蚪porny成人天涯| 不卡av在线网| 成人三级在线视频| 国产激情视频一区二区在线观看| 久久99国产精品麻豆| 日本sm残虐另类| 久久国产乱子精品免费女| 日韩av在线播放中文字幕| 婷婷开心久久网| 丝袜美腿亚洲一区| 美腿丝袜亚洲三区| 麻豆精品视频在线观看| 麻豆国产欧美日韩综合精品二区 | 国产欧美一区视频| 国产午夜精品一区二区| 国产精品毛片久久久久久| 国产精品久久久99| 亚洲男同性视频| 亚洲午夜视频在线| 日韩高清一区二区| 久久精品国产精品亚洲精品| 国产伦精品一区二区三区视频青涩| 久久成人麻豆午夜电影| 国产经典欧美精品| av毛片久久久久**hd| 91精品福利视频| 欧美精品乱人伦久久久久久| 欧美一级片在线看| 国产亚洲欧美日韩日本| 中文字幕中文字幕在线一区| 亚洲在线一区二区三区| 免费在线视频一区| 国产成人亚洲综合a∨猫咪| 色综合天天视频在线观看 | 久久99久久99小草精品免视看| 麻豆精品一二三| 不卡的电视剧免费网站有什么| 欧美在线999| 精品va天堂亚洲国产| 国产精品久久夜| 亚洲成人综合网站| 国产在线视频不卡二| 色香色香欲天天天影视综合网| 欧美精选一区二区| 久久久久久久久久久久久女国产乱 | 国产精品久久久久影院| 亚洲最大成人网4388xx| 久久精品久久久精品美女| 成人午夜精品一区二区三区| 欧美无人高清视频在线观看| 精品久久99ma| 亚洲猫色日本管| 激情成人综合网| 在线欧美日韩国产| 精品国产一区二区三区av性色 | 亚洲国产视频直播| 国产麻豆精品95视频| 色综合色狠狠综合色| 精品国产免费久久| 一二三区精品视频| 久久99国产精品久久| 欧美在线小视频| 亚洲国产成人在线| 美国精品在线观看| 欧美三级视频在线播放| 欧美激情一区二区三区不卡| 日本不卡一二三区黄网| 91在线无精精品入口| www久久久久| 日韩av中文字幕一区二区三区| 99精品欧美一区二区蜜桃免费| 337p日本欧洲亚洲大胆色噜噜| 亚洲国产精品一区二区尤物区| 成人性色生活片免费看爆迷你毛片| 欧美高清性hdvideosex| 综合精品久久久| 国产精品一区二区三区99| 欧美日本一区二区在线观看| 亚洲日本丝袜连裤袜办公室| 国产麻豆精品一区二区| 欧美大白屁股肥臀xxxxxx| 亚洲午夜三级在线| 91麻豆精品一区二区三区| 国产三级一区二区| 国产大陆精品国产| 久久精品人人做人人爽人人| 日本视频一区二区| 欧美日韩免费视频| 亚洲电影一区二区| 欧美日韩视频一区二区| 亚洲国产精品久久久久秋霞影院| 91麻豆免费观看| 亚洲精品日产精品乱码不卡| av成人免费在线| 国产精品嫩草99a| 99国产精品99久久久久久| 日本一区二区三区在线观看| 国产成人精品影院| 中文字幕av不卡| 99久久精品一区| 亚洲丝袜美腿综合| 在线精品视频免费播放| 一区二区激情视频| 欧美日韩精品二区第二页| 亚洲va韩国va欧美va精品| 欧美日韩国产不卡| 久久精品噜噜噜成人av农村| 精品久久久三级丝袜| 国产在线精品一区二区三区不卡| 欧美电影免费观看高清完整版在线| 免费xxxx性欧美18vr| wwww国产精品欧美| 成人精品gif动图一区| 亚洲人成在线播放网站岛国| 91精品1区2区| 无码av免费一区二区三区试看| 欧美挠脚心视频网站| 久久99精品久久久久久国产越南| 精品免费国产一区二区三区四区| 国产精品亚洲第一区在线暖暖韩国 | 久久九九影视网| av福利精品导航| 亚洲午夜精品久久久久久久久| 欧美日韩一区二区三区在线| 免费在线观看精品| 国产欧美日韩综合| 91免费观看国产| 亚洲福利视频一区二区| 欧美成人一级视频| youjizz久久| 亚洲香肠在线观看| 久久品道一品道久久精品| 成人av网站在线| 人人爽香蕉精品| 亚洲欧美在线高清| 91精品国模一区二区三区|