亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
国产乱码精品一区二区三区av| 成人午夜免费电影| 91国内精品野花午夜精品| 亚洲三级在线播放| 欧美中文字幕一二三区视频| 亚洲日本va午夜在线影院| 色88888久久久久久影院野外| 亚洲国产另类av| 欧美一级日韩不卡播放免费| 久久国产精品99久久久久久老狼| 2024国产精品| av一二三不卡影片| 亚洲动漫第一页| 日韩一级片在线播放| 麻豆精品一区二区综合av| 久久综合狠狠综合| a在线播放不卡| 亚洲va欧美va国产va天堂影院| 欧美一区二区观看视频| 国产精品中文字幕日韩精品 | 欧美精品丝袜久久久中文字幕| 婷婷成人激情在线网| 精品国精品国产尤物美女| 成人自拍视频在线| 午夜精品久久久久久久蜜桃app| 日韩美女在线视频| www.日韩av| 日本va欧美va精品发布| 亚洲国产成人一区二区三区| 91免费视频网址| 久久国产日韩欧美精品| 亚洲伦理在线精品| 欧美不卡在线视频| 一本大道久久a久久精品综合| 日韩不卡一二三区| 日韩va亚洲va欧美va久久| 国产欧美精品在线观看| 欧美日韩在线不卡| 播五月开心婷婷综合| 日本欧美加勒比视频| 亚洲欧美视频在线观看视频| 精品久久久三级丝袜| 在线影院国内精品| 粉嫩嫩av羞羞动漫久久久| 日韩中文字幕区一区有砖一区 | 天天色综合天天| 捆绑变态av一区二区三区| 欧美一区二区三区的| 日韩av二区在线播放| 欧美午夜精品免费| 亚洲国产日韩av| 欧美日韩国产一区| 五月天激情小说综合| 日本韩国精品一区二区在线观看| 亚洲免费观看高清在线观看| 不卡视频在线看| 亚洲视频一区在线观看| 99久久精品国产一区| 一区二区三区四区激情| 久久影院午夜论| 8x8x8国产精品| 日韩三级在线观看| 精品处破学生在线二十三| 久久国产麻豆精品| 91网上在线视频| 亚洲天堂2014| 6080日韩午夜伦伦午夜伦| 岛国一区二区三区| 99国产一区二区三精品乱码| 在线视频你懂得一区二区三区| 中文av字幕一区| 精品捆绑美女sm三区| 91精品国产美女浴室洗澡无遮挡| 色婷婷久久久久swag精品| 日韩一级免费观看| 日韩一区二区在线免费观看| 欧美日韩免费高清一区色橹橹| 在线免费av一区| 欧美性色黄大片| 欧美日韩成人一区| 欧美一卡二卡三卡| 欧美一级黄色录像| 精品成a人在线观看| 欧美精彩视频一区二区三区| 国产精品久久久久国产精品日日| 亚洲天堂2014| 亚洲成人激情自拍| 美女视频一区二区| 国产成人免费在线| 97精品国产97久久久久久久久久久久| av成人老司机| 欧美日韩一区在线| 欧美一级片免费看| 久久久久久久精| 亚洲丝袜制服诱惑| 天堂精品中文字幕在线| 麻豆专区一区二区三区四区五区| 国产精品资源网站| 色综合视频在线观看| 欧美日韩国产综合久久| 26uuu精品一区二区| 中文字幕欧美一| 香蕉成人伊视频在线观看| 奇米影视一区二区三区| 国产成人在线视频网站| 91高清视频免费看| 欧美一级欧美三级| 国产精品家庭影院| 丝瓜av网站精品一区二区| 国产精品18久久久久| 在线观看日韩国产| 国产偷国产偷精品高清尤物| 一区二区三区.www| 狠狠网亚洲精品| 欧美性一级生活| 久久精品一区四区| 亚洲第一二三四区| 国产福利91精品一区| 欧美色欧美亚洲另类二区| 亚洲精品一区二区三区四区高清| 国产精品二区一区二区aⅴ污介绍| 午夜一区二区三区在线观看| 国产一区二区在线看| 91豆麻精品91久久久久久| 精品久久国产老人久久综合| 亚洲日本在线天堂| 国内一区二区视频| 欧美猛男超大videosgay| 国产午夜三级一区二区三| 亚洲国产视频a| 91在线云播放| 久久久久久久久伊人| 天天爽夜夜爽夜夜爽精品视频| 成人午夜免费视频| 亚洲精品一区二区精华| 亚洲一区二区视频| 成a人片亚洲日本久久| 欧美一级黄色录像| 亚洲一区视频在线观看视频| 懂色av一区二区夜夜嗨| 精品美女一区二区| 午夜a成v人精品| 在线免费不卡视频| 亚洲欧美激情视频在线观看一区二区三区 | 亚洲一区二区三区国产| 国产成人免费视频精品含羞草妖精| 欧美一区二区三区免费观看视频| 亚洲人成网站精品片在线观看| 国产一区二区视频在线| 日韩一区二区电影在线| 婷婷一区二区三区| 欧美揉bbbbb揉bbbbb| 亚洲精品精品亚洲| 国产精品女同互慰在线看 | 国产成人精品一区二区三区四区| 欧美一区二区三区视频在线| 日韩电影在线免费观看| 欧美日韩视频一区二区| 婷婷亚洲久悠悠色悠在线播放| 欧美日韩一区在线| 美腿丝袜亚洲色图| 亚洲视频在线观看三级| 欧洲亚洲精品在线| 美女一区二区三区在线观看| 久久综合九色综合久久久精品综合| 国产成人免费在线观看| 国产精品福利一区二区三区| 欧美美女网站色| 国产成人精品aa毛片| 亚洲第一福利视频在线| 精品日韩欧美在线| 91搞黄在线观看| 国产精品一区二区在线观看不卡| 中文字幕av一区二区三区| 日韩欧美另类在线| 日韩三级在线免费观看| 精品国产乱码久久久久久老虎 | 欧美一区二区免费视频| 欧美日韩国产精品成人| 蜜桃av一区二区在线观看| 欧美二区乱c少妇| 一本一本大道香蕉久在线精品| 久久电影网站中文字幕| 亚洲综合在线电影| 国产专区综合网| 精品国产乱码久久久久久图片 | 国产精品私人自拍| 欧美亚洲国产一卡| 天天色天天操综合| 日韩亚洲国产中文字幕欧美| 国产乱码精品一区二区三| 国产精品网曝门| 欧美性受xxxx| 精品中文字幕一区二区| 国产欧美日本一区二区三区| 91麻豆swag| 久久精品国产免费| 亚洲婷婷综合久久一本伊一区 | 色婷婷综合久久| 日本在线不卡一区|