亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
婷婷国产v国产偷v亚洲高清| 国产精品二区一区二区aⅴ污介绍| 亚洲曰韩产成在线| 91视视频在线观看入口直接观看www | 国产欧美一区二区精品性色| 国产v综合v亚洲欧| 国产日韩欧美在线一区| 丁香一区二区三区| 亚洲精选在线视频| 欧美一区二区精品久久911| 国产一区二区三区日韩| 国产欧美日韩在线看| 99综合电影在线视频| 亚洲激情图片一区| 日韩欧美一区二区在线视频| 国产成人精品一区二| 亚洲视频精选在线| 日韩亚洲欧美中文三级| 国产精品一二三区| 一区二区三区日韩欧美精品| 4438成人网| 成人黄色在线看| 日韩中文欧美在线| 国产欧美日韩一区二区三区在线观看| 91社区在线播放| 裸体歌舞表演一区二区| 中文字幕亚洲综合久久菠萝蜜| 欧美日韩亚洲综合| 国产精品影视天天线| 亚洲国产精品天堂| 久久综合狠狠综合| 欧美日韩精品二区第二页| 捆绑紧缚一区二区三区视频| 国产精品三级av在线播放| 欧美精品三级在线观看| 国产91精品久久久久久久网曝门| 亚洲国产一区在线观看| 国产丝袜美腿一区二区三区| 欧美午夜不卡视频| 从欧美一区二区三区| 亚洲mv大片欧洲mv大片精品| 中文字幕乱码亚洲精品一区| 3d成人h动漫网站入口| 成人免费看片app下载| 亚洲成人av免费| 亚洲欧美综合网| 欧美刺激脚交jootjob| 91精品1区2区| 懂色av噜噜一区二区三区av| 麻豆精品在线视频| 亚洲成人7777| 亚洲免费av网站| 国产欧美精品在线观看| 日韩欧美一区在线观看| 欧美日韩二区三区| 91年精品国产| 不卡免费追剧大全电视剧网站| 久久成人18免费观看| 日韩av电影天堂| 亚洲成人av一区二区三区| 亚洲女同女同女同女同女同69| 久久久影院官网| 精品国产一区二区亚洲人成毛片| 欧美三级在线视频| 欧美日韩一级视频| 欧美日韩视频一区二区| 在线视频综合导航| 一道本成人在线| 91在线精品一区二区| 成a人片国产精品| 成av人片一区二区| 色综合久久中文字幕| 99精品欧美一区二区三区小说| 懂色av一区二区在线播放| 国产精品一区二区91| 国产成人aaa| 国产成人精品亚洲日本在线桃色 | 久久蜜桃av一区精品变态类天堂| 91精品在线观看入口| 欧美日韩一区二区三区不卡| 9191国产精品| 日韩欧美一级在线播放| 欧美成人福利视频| 久久久久国产精品麻豆ai换脸 | 日韩欧美在线一区二区三区| 555www色欧美视频| 日韩欧美亚洲另类制服综合在线| 精品乱码亚洲一区二区不卡| 337p粉嫩大胆色噜噜噜噜亚洲| 久久久精品tv| 中文字幕一区不卡| 亚洲一区中文在线| 九色综合狠狠综合久久| 国产精品一二三四区| 91老司机福利 在线| 欧美色综合久久| 日韩午夜激情免费电影| 国产午夜一区二区三区| 亚洲欧洲一区二区三区| 亚洲高清不卡在线| 热久久免费视频| 激情六月婷婷综合| 91同城在线观看| 欧美日韩国产综合视频在线观看| 欧美大片在线观看一区二区| 亚洲国产精品av| 亚洲另类中文字| 日韩二区三区在线观看| 国产黄色精品视频| 91成人免费在线视频| 精品久久久久久久人人人人传媒| 国产日本欧美一区二区| 亚洲高清视频的网址| 黄色成人免费在线| 成人a区在线观看| 69p69国产精品| 中文字幕亚洲一区二区va在线| 亚洲国产日韩精品| 国产精品99久久久久久久vr| 欧美在线不卡视频| 日韩欧美一区在线| 亚洲最新在线观看| 国产精品自拍毛片| 777午夜精品免费视频| 国产精品美女一区二区三区| 天天操天天综合网| 不卡高清视频专区| 精品久久久久久久久久久久久久久久久 | 久久精品国产亚洲一区二区三区| 国产精品一区二区免费不卡| 在线精品视频一区二区三四| 久久久www成人免费毛片麻豆| 亚洲成人免费观看| 成人国产精品视频| 91精品国产欧美一区二区成人 | 国产乱码精品一区二区三 | 亚洲一级二级在线| 国产精品亚洲第一区在线暖暖韩国 | 久久久久久亚洲综合影院红桃| 亚洲精品福利视频网站| 国产成人福利片| 日韩欧美一级精品久久| 午夜欧美2019年伦理| 91在线视频观看| 国产精品看片你懂得| 国产一区二区h| 精品日韩99亚洲| 日韩影院精彩在线| 欧美日韩视频一区二区| 依依成人综合视频| 91在线视频官网| 亚洲同性同志一二三专区| 成人听书哪个软件好| 欧美精品一区二区三区在线 | 国产日韩精品久久久| 美女一区二区视频| 欧美一级艳片视频免费观看| 午夜国产不卡在线观看视频| 欧美羞羞免费网站| 一区二区久久久| 91免费看`日韩一区二区| 中文字幕精品在线不卡| 大白屁股一区二区视频| 日本一区二区三区国色天香 | 久久综合九色综合欧美98 | 国产精品伦理在线| 国产成人精品亚洲777人妖| 国产欧美一区二区在线| 国产剧情在线观看一区二区| 精品国产一区二区亚洲人成毛片| 久久精品国产一区二区三| 日韩女优电影在线观看| 久久99精品久久久久婷婷| 精品久久国产老人久久综合| 紧缚奴在线一区二区三区| 精品区一区二区| 国产馆精品极品| 国产精品二区一区二区aⅴ污介绍| 成人av电影观看| 亚洲精品高清视频在线观看| 欧美日韩免费在线视频| 日韩一区精品字幕| 久久免费看少妇高潮| www.亚洲色图| 亚洲大型综合色站| 日韩一区国产二区欧美三区| 激情文学综合插| 综合久久国产九一剧情麻豆| 欧美图区在线视频| 久久精品国产一区二区三 | 欧美一区二区三区在线观看| 久久国产三级精品| 国产精品久久久久久久蜜臀| 在线精品视频小说1| 美腿丝袜亚洲三区| 国产精品国产成人国产三级| 欧美熟乱第一页| 久久99国产精品麻豆| 中文字幕五月欧美| 欧美一区二区三区性视频|