ImageVerifierCode 换一换
格式:DOC , 页数:17 ,大小:73KB ,
资源ID:4514750      下载积分:5 金币
验证码下载
登录下载
邮箱/手机:
验证码: 获取验证码
温馨提示:
支付成功后,系统会自动生成账号(用户名为邮箱或者手机号,密码是验证码),方便下次登录下载和查询订单;
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/4514750.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  
声明  |  会员权益     获赠5币     写作写作

1、填表:    下载求助     索取发票    退款申请
2、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
3、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
4、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
5、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前自行私信或留言给上传者【二***】。
6、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
7、本文档遇到问题,请及时私信或留言给本站上传会员【二***】,需本站解决可联系【 微信客服】、【 QQ客服】,若有其他问题请点击或扫码反馈【 服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【 版权申诉】”(推荐),意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:4008-655-100;投诉/维权电话:4009-655-100。

注意事项

本文(Windows平台下的多线程编程(计算机论文翻译).doc)为本站上传会员【二***】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4008-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

Windows平台下的多线程编程(计算机论文翻译).doc

1、附录AUnder theWindowsplatform, multi-threaded programmingA thread is a process execution path, it contains separate stack andCPUregister state, the process of each thread to share all resources, including open files, signal identification and dynamic allocation of memory and so on.All threads within a

2、 process using the same address space, and these threads of execution by the system scheduler control thread scheduler to decide which and when to execute the executable threads.Thread has priority, lower priority thread must wait until the higher priority thread after their implementation.In the mu

3、lti-processor machines, the scheduler can be multiple threads running up into different processors, it will give the processor the task balance, and improve efficiency of the system.Windowsis a multitasking operating system, a process inWindowscontains one or more threads.32-bit WindowsenvironmentWi

4、n32 APIprovides a multi-threaded application development interface functions required, and use of VC in the standard C libraries are also provided to develop multithreaded applications, the corresponding MFC class library encapsulates the class of multi-threaded programming users in the development

5、can be based on the needs and characteristics of the application select the appropriate tool.In order so that we can fully understand theWindowsmulti-threaded programming techniques, this article will focus onWin32 APIandMFCare two ways of how to prepare multi-threaded programs.Multithreaded Program

6、ming inWin32andMFCclass library under way to support the principle is the same, the main thread of the process at any time needed to create a new thread.When the thread has finished, automatically terminate the thread; when the process is complete, all threads are terminated.Threads share the proces

7、s of all activities of resources, therefore, be considered when programming multiple threads access the same resource conflict problem.When a thread is accessing a process object, and another thread to change the object, it may produce incorrect results, programming to solve this conflict.Under the

8、multi-threadedWin32 APIprogramming:Win32 APIis theWindowsoperating system kernel and the interface between applications, which will provide the functions of the kernel function wrapper, the application obtained by calling the correlation function of the corresponding system function.In order to prov

9、ide multi-threading applications,Win32 APIfunction provides some focus on procedures for handling multi-threaded set of functions.Directly with theWin32 APIto program design has many advantages: Win32-based application code execution is small, high efficiency, but it requires programmers to write co

10、de more, and all systems need to manage the resources available to the program.Programming with theWin32 APIdirectly on theWindowssystem kernel programmer is required to have a certain understanding, it will take a lot of time on the programmer to manage system resources, thus reducing the efficienc

11、y of the programmer.1.With theWin32function to create and terminate threadsWin32function library provides a function of multi-threaded operation, including creating threads, terminate threads, the establishment of exclusive zones.In the applications main thread or other activities to create a new th

12、read thread function is as follows:HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes,DWORDdwStackSize,LPTHREAD_START_ROUTINElpStartAddress,LPVOIDlpParameter,DWORDdwCreationFlags,LPDWORDlpThreadId);HANDLE CreateThread (LPSECURITY_ATTRIBUTES lpThreadAttributes, DWORD dwStackSize, LPTHREAD_S

13、TART_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);If you create a successful thread handle is returned, otherwise NULL.Create a new thread, the thread started to execute.However, if used indwCreationFlags CREATE_SUSPENDEDproperty, then the thread is not imme

14、diately executed, but the first suspended, until the calls started afterResumeThreadthreads in the process can call the following function to set the priority of the thread:BOOL SetThreadPriority(HANDLE hThread,intnPriority);BOOL SetThreadPriority (HANDLE hThread, intnPriority);When the function ret

15、urns the calling thread, the thread automatically terminates.If you need to terminate during the execution of the thread can call the function:VOID ExitThread(DWORD dwExitCode);VOID ExitThread (DWORD dwExitCode);If you terminate a thread in the thread on the outside, you can call the following funct

16、ion:BOOL TerminateThread(HANDLE hThread,DWORDdwExitCode);BOOL TerminateThread (HANDLE hThread, DWORD dwExitCode);It should be noted: this function may cause system instability, and the thread does not release the occupied resources.Therefore, under normal circumstances, it is recommended not to use

17、this function.If you want to terminate the thread is the last thread within the process, the thread is terminated after the corresponding process should be terminated.2.Thread synchronizationIn the thread body, if the thread is completely independent data access with other threads and other resource

18、s without conflict operation, the method can be carried out in accordance with generally single-threaded programming.However, the situation in multi-threaded processing is often not the case, often between threads simultaneously access some resources.Because access to shared resources causes conflic

19、t is inevitable, in order to address this thread synchronization problems,Win32 APIprovides a variety of synchronization objects to help programmers access to shared resources to resolve the conflict.In presenting these synchronization objects introduce wait functions before, because all the control

20、 objects access control should use this function.Win32 APIprovides a set of threads can block waiting for the implementation of its own function.These functions in its argument object generates one or more synchronization signal, or exceeds the waiting time will be returned.Waiting function is not r

21、eturned, the threads in a wait state, when the thread consumes very littleCPUtime.Not only can guarantee the wait function using thread synchronization, but also can improve the running efficiency.Waiting function is the most commonly used:DWORD WaitForSingleObject(HANDLE hHandle,DWORD dwMillisecond

22、s);DWORD WaitForSingleObject (HANDLE hHandle, DWORD dwMilliseconds);The function can be used to simultaneously monitor multipleWaitForMultipleObjectsynchronization object, the function is declared as:DWORD WaitForMultipleObject(DWORD nCount,CONST HANDLE *lpHandles,BOOLbWaitAll,DWORDdwMilliseconds);D

23、WORD WaitForMultipleObject (DWORD nCount, CONST HANDLE * lpHandles, BOOL bWaitAll, DWORD dwMilliseconds);(1)mutex objectMutexstate of the object by any thread in that it does not have a time signal, it was a time when no signal.Mutexobjects are suitable for coordination of multiple threads exclusive

24、 access to shared resources.The following steps can use the object:First, create a mutex object, get the handle:HANDLE CreateMutex();HANDLE CreateMutex ();Then, in the thread before the possible areas of conflict (ie, before access to shared resources) calls WaitForSingleObject, the handle to the fu

25、nction, the request takes mutex object:dwWaitResult = WaitForSingleObject(hMutex,5000L);dwWaitResult = WaitForSingleObject (hMutex, 5000L);Shared resources conclusion of the visit, the release of the occupation of the mutex object:ReleaseMutex(hMutex);ReleaseMutex (hMutex);Mutex object at the same t

26、ime can only be occupied by a thread, when the mutex object is occupied by a thread when another thread would like to take it if you must wait until after the release of the previous thread to succeed.(2)signal objectSignal objects allow multiple threads simultaneously access shared resources in the

27、 creation of object may also specify the maximum number of threads access.When a thread successfully apply for access to the signal by a counter object, callReleaseSemaphorefunction, the signal object counter plus one.Among them, the counter value is greater than or equal to 0, but less than or equa

28、l to the maximum specified when created.If an application to create a signal object, the initial value of its counter is set to 0 to block the other thread to protect the resources.And other initialization is complete, callReleaseSemaphorefunction will increase to its maximum value the counter, you

29、can access a normal visit.The following steps can use the object:First, create the signal object:HANDLE CreateSemaphore();HANDLE CreateSemaphore ();A signal or open object:HANDLE OpenSemaphore();HANDLE OpenSemaphore ();Then, access to shared resources in the thread before calling WaitForSingleObject

30、.After access to shared resources should be occupied by the release of the signal objects:ReleaseSemaphore ();(3) the event objectEvent object(Event)is the simplest synchronization objects, which includes both signal and no signal state.Threads access a resource, you need to wait for some event to o

31、ccur, then the most appropriate to use the event object.For example: only the data received in the communication port buffer, the monitor thread is activated.The event object is created withCreateEventfunction.This function can be specified event object class and the initial state of the event.If th

32、e manual reset event, it always maintained a signal pick-likeBa BanesetEventfunction reset to no signal events.If the event is automatically reset, then its state after the release of a single waiting thread will automatically become free signal.SetEventWithSetEventcan set the event object to signal

33、ed.OpenEventIn the establishment of event, named for the object, so that other threads in the process can be used to open the specified function nameOpenEventevent object handle.(4)exclusion zone objectAsynchronous execution in the exclusion zone, it can only be in the same process of dealing with s

34、hared resources between threads.At a time when several methods described above can be used, however, the use of exclusion zones approach makes more efficient synchronization management.CRITICAL_SECTIONused to define a structure of exclusion zone object is called before the process using the followin

35、g function to initialize the object:VOID InitializeCriticalSection(LPCRITICAL_SECTION);VOID InitializeCriticalSection (LPCRITICAL_SECTION);When a thread uses the exclusion zone, call the function:EnterCriticalSectionorTryEnterCriticalSection;When asked to take exit exclusion zone, call the function

36、LeaveCriticalSection, the release of the exclusion zone occupied by the object for other threads.MFC-based multi-threaded programming:Microsofts VC+ + MFCis to provide an integrated environment based library for programmers, it uses the class library to encapsulateWin32 APIway to class provided to d

37、evelopers.Because of its fast, simple, powerful and so loved by the majority of developers.Therefore, it is recommended to useMFCclass library application development.InVC + +with theMFCclass library, provides support for multithreaded programming, basic principles and design based on the sameWin32A

38、PI, butMFCsynchronization objects on a wrapper, so to achieve more convenient to avoid the object handle management the tedious work.In MFC, the thread is divided into two types: worker threads and user interface thread.Work earlier in the thread with the same thread, the thread is a user interface

39、to receive user input, handle events, and message threads.1.Worker threadRelatively simple work-thread programming, design ideas and the mentioned earlier the same: a basic function represents a thread, create and start the thread, the thread into the running state; if the thread is used to share re

40、sources, the need for resource synchronization.In this way create a thread and start the thread can call the function:CWinThread*AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam,intnPriority= THREAD_PRIORITY_NORMAL,UINT nStackSize =0,DWORD dwCreateFlags=0, LPSECURITY_ATTRIBUTES lpSecurity

41、Attrs = NULL);UINT ThreadFunction( LPVOID pParam)。CWinThread * AfxBeginThread (AFX_THREADPROC pfnThreadProc, LPVOID pParam, intnPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);parameterpfnThreadProcis the thread of execut

42、ion, function prototype is:UINT ThreadFunction (LPVOID pParam).Parameter is passed to the implementation ofpParamargument;Parameter is the threadnPriorityrights, optional values:HREAD_PRIORITY_NORMAL、THREAD_PRIORITY_LOWEST、THREAD_PRIORITY_HIGHEST、THREAD_PRIORITY_IDLE。THREAD_PRIORITY_NORMAL, THREAD_P

43、RIORITY_LOWEST, THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_IDLE.ParameterdwCreateFlagsis a sign of the thread is created, you can value CREATE_SUSPENDED, that thread is created in a suspended state, calledResumeThreadthread continues to run after the function, or the value of 0indicatesa thread is cre

44、ated after running.CWinThreadclass object return value is a pointer, its member variablesm_hThreadfor the thread handle, in the way ofWin32 APIfunctions that operate under the parameters of the thread are required to provide a handle to the thread, so when the thread is created you can use all theWi

45、n32 APIfunctionpWinThread -m_Threadthread related operations.Note: If a class object to create and start the thread, the thread function should be defined as global functions outside the class.2. Theuser interface threadMFC-based applications have an application object, which isCWinAppderived class

46、object that represents the application process, the main thread.When the thread and exit the thread is executed, because no other threads in the process, the process ends automatically.ClassCWinApp derived from theCWinThread,CWinThread user interface thread is the basic class.We write the user inter

47、face thread, you need to derive fromCWinThread thread of our own class,ClassWizardcan help us do this work.First useClassWizardto derive a new class, set the base class CwinThread.Note: The classDECLARE_DYNCREATEandIMPLEMENT_DYNCREATEmacros are necessary because you need to create threads dynamicall

48、y created class object.Necessary initialization and exit code can be placed in the class, respectively, andExitInstancefunction InitInstance.If you need to create a window, can be done in theInitInstancefunction.And then create a thread and start the thread.Two methods can be used to create the user

49、 interface thread,MFCprovides two versions of theAfxBeginThreadfunction, one used to create the user interface thread.The second method is divided into two steps: first, the calling thread class constructor creates a thread object; Second, callCWinThread:CreateThreadfunction to create the thread.After the establishment and start the thread, the thread function in the process of implementation has been effective.If the thread object,

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服