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

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

?? lion-tutorial15.htm

?? 內有一些代碼
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<html>

<head>
<link rel="stylesheet" href="../../asm.css">

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Iczelion's win32 asm tutorial</title>
</head>

<body bgcolor="#FFFFFF" background="../../images/back01.jpg">
<p align="center">Tutorial 15: Multithreading Programming</p>
<hr size="1">
<strong> </strong> We will learn how to create a multithreading program in this 
tutorial. We also study the communication methods between the threads. 
<p>Download the example <a href="files/tut15.zip">here</a>. 
<h3> Theory:</h3>
In previous tutorial, you learn the a process consists of at least one thread: 
the primary thread. A thread is a chain of execution. You can also create additional 
threads in your program. You can view multithreading as multitasking within one 
program. In term of implementation, a thread is a function that runs concurrently 
with the main program. You can run several instances of the same function or you 
can run several functions simultaneously depending on your requirement. Multithreading 
is specific to Win32, no Win16 counterpart exists. <br>
Threads run in the same process so they can access any resources in the process 
such as global variables, handles etc. However, each thread has its own stack 
so local variables in each thread are private. Each thread also owns its private 
register set so when Windows switches to other threads, the thread can "remember" 
its last status and can "resume" the task when it gains control again. This is 
handled internally by Windows. <br>
We can divide threads into two caterories: 
<ol>
  <li> User interface thread: This type of thread creates its own window so it 
    receives windows messages. It can respond to the user via its own window hence 
    the name. This type of thread is subject to Win16 Mutex rule which allows 
    only one user interface thread in 16-bit user and gdi kernel. While a user 
    interface thread is executing code in 16-bit user and gdi kernel, other UI 
    threads cannot use the service of the 16-bit user and gdi kernel. Note that 
    this Win16 Mutex is specific to Windows 95 since underneath, Windows 95 API 
    functions thunk down to 16-bit code. Windows NT has no Win16 Mutex so the 
    user interface threads under NT work more smoothly than under Windows 95.</li>
  <li> Worker thread: This type of thread does not create a window so it cannot 
    receive any windows message. It exists primarily to do the assigned job in 
    the background hence the name worker thread.</li>
</ol>
I advise the following strategy when using multithreading capability of Win32: 
Let the primary thread do user interface stuff and the other threads do the hard 
work in the background. In this way, the primary thread is like a Governor, other 
threads are like the Governor's staff. The Governor delegates jobs to his staff 
while he maintains contact with the public. The Governor staff obediently performs 
the work and reports back to the Governor. If the Governor were to perform every 
task himself, he would not be able to give much attention to the public or the 
press. That's akin to a window which is busy doing a lengthy job in its primary 
thread: it doesn't respond to the user until the job is completed. Such a program 
can benefit from creating an additonal thread which is responsible for the lengthy 
job, allowing the primary thread to respond to the user's commands. <br>
We can create a thread by calling CreateThread function which has the following 
syntax: 
<p><b>CreateThread proto lpThreadAttributes:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  dwStackSize:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  lpStartAddress:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  lpParameter:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  dwCreationFlags:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  lpThreadId:DWORD</b> 
<p>CreateThread function looks a lot like CreateProcess. <br>
  <b>lpThreadAttributes</b>&nbsp; --> You can use NULL if you want the thread 
  to have default security descriptor. <br>
  <b>dwStackSize</b> --> specify the stack size of the thread. If you want the 
  thread to have the same stack size as the primary thread, use NULL as this parameter. 
  <br>
  <b>lpStartAddress</b>--> Address of the thread function.It's the function that 
  will perform the work of the thread. This function MUST receive one and only 
  one 32-bit parameter and return a 32-bit value. <br>
  <b>lpParameter</b>&nbsp; --> The parameter you want to pass to the thread function. 
  <br>
  <b>dwCreationFlags</b> --> 0 means the thread runs immediately after it's created. 
  The opposite is CREATE_SUSPENDED flag. <br>
  <b>lpThreadId</b> --> CreateThread function will fill the thread ID of the newly 
  created thread at this address. 
<p>If CreateThread call is sucessful, it returns the handle of the newly created 
  thread. Otherwise, it returns NULL. <br>
  The thread function runs as soon as CreateThread call is success ful unless 
  you specify CREATE_SUSPENDED flag in dwCreationFlags. In that case, the thread 
  is suspended until ResumeThread function is called. <br>
  When the thread function returns with ret instruction, Windows calls ExitThread 
  function for the thread function implicitly. You can call ExitThread function 
  with in your thread function yourself but there' s little point in doing so. 
  <br>
  You can retrieve the exit code of a thread by calling GetExitCodeThread function. 
  <br>
  If you want to terminate a thread from other thread, you can call TerminateThread 
  function. But you should use this function under extreme circumstance since 
  this function terminates the thread immediately without giving the thread any 
  chance to clean up after itself. 
<p>Now let's move to the communication methods between threads. <br>
  There are three of them: 
<ul>
  <li> Using global variables</li>
  <li> Windows messages</li>
  <li> Event</li>
</ul>
Threads share the process's resources including global variables so the threads 
can use global varibles to communicate with each other. However this method must 
be used with care. Thread synchronization must enter into consideration. For example, 
if two threads use the same structure of 10 members , what happens when Windows 
suddenly yanks the control from one of the thread when it was in the middle of 
updating the structure? The other thread will be left with an inconsistent data 
in the structure! Don't make any mistake, multithreading programs are harder to 
debug and maintain. This sort of bug seems to happen at random which is very hard 
to track down. <br>
You can also use Windows messages to communicate between threads. If the threads 
are all user interface ones, there's no problem: this method can be used as a 
two-way communication. All you have to do is defining one or more custom windows 
messages that are meaningful to the threads. You define a custom message by using 
WM_USER message as the base value say , you can define it like this: 
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WM_MYCUSTOMMSG equ WM_USER+100h 
<p>Windows will not use any value from WM_USER upward for its own messages so 
  you can use the value WM_USER and above as your own custom message value. <br>
  If one of the thread is a user interface thread and the other is a worker one, 
  you cannot use this method as two-way communication since a worker thread doesn't 
  have its own window so it doesn't have a message queue. You can use the following 
  scheme: 
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  User interface Thread ------> global variable(s)----> Worker thread <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  Worker Thread&nbsp; ------> custom window message(s) ----> User interface Thread 
<p>In fact, we will use this method in our example. <br>
  The last communication method is an event object. You can view an event object 
  as a kind of flag. If the event object is in "unsignalled" state, the thread 
  is dormant or sleeping, in this state, the thread doesn't receive CPU time slice. 
  When the event object is in "signalled" state,Windows "wakes up" the thread 
  and it starts performing the assigned task. 
<h3> Example:</h3>
You should download the example zip file and run thread1.exe. Click the "Savage 
Calculation" menu item. This will instruct the program to perform "add eax,eax 
" for 600,000,000 times. Note that during that time, you cannot do anything with 
the main window: you cannot move it, you cannot activate its menu, etc. When the 
calculation is completed, a message box appears. After that the window accepts 
your command normally. <br>
To avoid this type of inconveniece to the user, we can move the "calculation" 
routine into a separate worker thread and let the primary thread continue with 
its user interface task. You can see that even though the main window responds 
more slowly than usual,&nbsp; it still responds 
<p><b>.386</b> <br>
  <b>.model flat,stdcall</b> <br>
  <b>option casemap:none</b> <br>
  <b>WinMain proto :DWORD,:DWORD,:DWORD,:DWORD</b> <br>
  <b>include \masm32\include\windows.inc</b> <br>
  <b>include \masm32\include\user32.inc</b> <br>
  <b>include \masm32\include\kernel32.inc</b> <br>
  <b>includelib \masm32\lib\user32.lib</b> <br>
  <b>includelib \masm32\lib\kernel32.lib</b> 
<p><b>.const</b> <br>
  <b>IDM_CREATE_THREAD equ 1</b> <br>
  <b>IDM_EXIT equ 2</b> <br>
  <b>WM_FINISH equ WM_USER+100h</b> 
<p><b>.data</b> <br>
  <b>ClassName db "Win32ASMThreadClass",0</b> <br>
  <b>AppName&nbsp; db "Win32 ASM MultiThreading Example",0</b> <br>
  <b>MenuName db "FirstMenu",0</b> <br>
  <b>SuccessString db "The calculation is completed!",0</b> 
<p><b>.data?</b> <br>
  <b>hInstance HINSTANCE ?</b> <br>
  <b>CommandLine LPSTR ?</b> <br>
  <b>hwnd HANDLE ?</b> <br>
  <b>ThreadID DWORD ?</b> 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩欧美亚洲国产精品字幕久久久| 偷拍亚洲欧洲综合| 精品入口麻豆88视频| 91麻豆精品91久久久久同性| 欧美日韩国产片| 91精品国产一区二区人妖| 在线播放亚洲一区| 日韩欧美视频在线| 国产日韩欧美在线一区| 国产精品黄色在线观看| 一区二区三区免费在线观看| 一区二区三区波多野结衣在线观看| 亚洲乱码国产乱码精品精的特点| 一区二区三区欧美久久| 日韩二区三区在线观看| 国产一区在线观看视频| 成人永久免费视频| 色噜噜狠狠一区二区三区果冻| 欧美视频在线播放| 日韩精品一区二区三区四区| 中文字幕+乱码+中文字幕一区| 亚洲欧洲另类国产综合| 亚洲成人免费在线| 精品一区二区三区的国产在线播放| 美女脱光内衣内裤视频久久影院| 国产成人亚洲综合a∨猫咪| 99re66热这里只有精品3直播| 在线亚洲高清视频| 久久品道一品道久久精品| 亚洲男人的天堂av| 蜜臀av一区二区在线免费观看| 国产91丝袜在线播放九色| 精品视频1区2区3区| 久久蜜桃av一区二区天堂| 亚洲一区二区三区四区中文字幕| 裸体在线国模精品偷拍| 97se亚洲国产综合自在线| 日韩一区二区免费高清| 亚洲色欲色欲www| 久久精品国产99| 日本久久电影网| 久久日韩精品一区二区五区| 一区二区三区成人| 国产成人亚洲精品狼色在线| 69堂精品视频| 亚洲欧美日本韩国| 国产精品一区二区在线播放| 欧美视频一区二区三区| 国产精品国产a| 国产乱码精品1区2区3区| 欧美男生操女生| 国产精品免费看片| 韩国欧美一区二区| 91精品国产欧美一区二区18| 一区二区三区欧美| 97精品久久久久中文字幕| 国产亚洲成av人在线观看导航| 天天做天天摸天天爽国产一区| 91最新地址在线播放| 国产欧美日韩亚州综合| 精品影院一区二区久久久| 欧美人妖巨大在线| 亚洲福中文字幕伊人影院| 91福利在线播放| 亚洲女子a中天字幕| 99久久久久久| ...中文天堂在线一区| 成人午夜激情视频| 国产精品狼人久久影院观看方式| 国产精品99久久久久| 欧美精品一区二区三区蜜桃视频| 男人的j进女人的j一区| 欧美一级xxx| 久久国产麻豆精品| 2019国产精品| 国产美女精品一区二区三区| 国产亚洲欧美在线| 国产成人免费视频一区| 欧美激情一区二区| 97精品久久久午夜一区二区三区| 亚洲欧洲日产国码二区| 色婷婷av一区| 午夜精品久久久| 欧美一区二区三区视频在线观看| 日韩精品成人一区二区三区| 91精品国产入口在线| 久久精品国产久精国产爱| 久久人人超碰精品| 99re热这里只有精品免费视频| 亚洲欧美欧美一区二区三区| 欧美日韩一区二区电影| 美女性感视频久久| 亚洲国产精品激情在线观看| av动漫一区二区| 亚洲一卡二卡三卡四卡无卡久久 | 喷水一区二区三区| 精品国产sm最大网站| 成人手机电影网| 亚洲另类春色国产| 欧美一级电影网站| 99麻豆久久久国产精品免费| 亚洲综合色噜噜狠狠| 精品国产乱码久久久久久夜甘婷婷| 国产精品996| 亚洲一区二区欧美日韩| 2017欧美狠狠色| 91麻豆免费观看| 免费成人美女在线观看| 亚洲欧洲国产专区| 91精品国产综合久久蜜臀 | 中文字幕五月欧美| 91精品国产综合久久小美女| 高清免费成人av| 日韩在线一二三区| 亚洲欧洲av在线| 欧美大胆人体bbbb| 欧美亚洲免费在线一区| 国产成人免费9x9x人网站视频| 亚洲一区二区三区四区五区黄 | 亚洲人成精品久久久久| 91精品国产91久久久久久一区二区 | 亚洲永久精品大片| 国产欧美一区二区精品性色| 欧美日韩国产中文| 91蜜桃在线免费视频| 狠狠色丁香久久婷婷综| 亚洲一区视频在线| 亚洲女同ⅹxx女同tv| 精品99999| 91精品国产色综合久久不卡蜜臀| 91欧美激情一区二区三区成人| 国内精品在线播放| 麻豆国产精品一区二区三区| 亚洲综合清纯丝袜自拍| 国产精品人人做人人爽人人添| 欧美电影免费提供在线观看| 欧美午夜片在线观看| 色婷婷av一区二区| 91蜜桃免费观看视频| 国产成人精品一区二区三区网站观看| 日韩成人免费看| 午夜激情一区二区三区| 一区二区三区色| 一区二区三区四区高清精品免费观看 | 天堂在线亚洲视频| 亚洲综合色成人| 亚洲大片精品永久免费| 一区二区三区视频在线观看| 亚洲色图色小说| 亚洲精品第一国产综合野| 亚洲人妖av一区二区| 1区2区3区精品视频| 亚洲精品中文字幕乱码三区| 亚洲人成伊人成综合网小说| 亚洲欧美一区二区三区极速播放| 中文字幕亚洲区| 一区二区视频免费在线观看| 一个色妞综合视频在线观看| 亚洲一区视频在线| 日韩avvvv在线播放| 日本v片在线高清不卡在线观看| 秋霞电影一区二区| 国产精品系列在线播放| 成人午夜视频免费看| 91免费小视频| 在线播放亚洲一区| 久久亚洲一区二区三区四区| 日本一区二区成人| 一区二区三区在线免费| 日本三级亚洲精品| 国产高清一区日本| 色综合久久中文综合久久97| 欧美日韩国产片| 久久一留热品黄| 一区二区在线观看视频在线观看| 亚洲成人7777| 国产成人在线网站| 在线视频你懂得一区二区三区| 欧美一区二区三区的| 欧美激情一区二区三区不卡| 亚洲亚洲精品在线观看| 久久成人免费网站| 99re6这里只有精品视频在线观看| 欧美日韩国产高清一区二区| 精品国精品自拍自在线| 国产精品国产三级国产aⅴ原创| 午夜精品久久久久久久99樱桃 | 亚洲丝袜自拍清纯另类| 国产精品一区免费视频| 色婷婷久久久综合中文字幕| 日韩区在线观看| 亚洲欧美激情小说另类| 免费成人深夜小野草| 色婷婷综合久久久| 久久久久国色av免费看影院| 亚洲一级片在线观看| fc2成人免费人成在线观看播放| 7777精品伊人久久久大香线蕉最新版 | 一本一本大道香蕉久在线精品| 欧美一级久久久|