教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

VC++技术内幕(windows编程篇)(17)

来源:网络收集 时间:2026-07-12
导读: 2)挂起线程: CWinThread::SuspendThread DWORD SuspendThread( ); //Return Value:The thread‘s previous suspend count if successful; 0xFFFFFFFF otherwise. //CWinThread::SuspendThread:Increments the c

2)挂起线程:

CWinThread::SuspendThread DWORD SuspendThread( );

//Return Value:The thread‘s previous suspend count if successful; 0xFFFFFFFF otherwise.

//CWinThread::SuspendThread:Increments the current thread‘s suspend(悬挂,延缓) count. If any thread has a suspend count above zero, that thread does not execute.

3)恢复线程运行: CWinThread::ResumeThread DWORD ResumeThread( );

//Return Value:The thread‘s previous suspend count if successful; 0xFFFFFFFF otherwise. If the return value is zero, the current thread was not suspended. If the return value is one, the thread was suspended, but is now restarted. Any return value greater than one means the thread remains suspended.

//Remarks:Called to resume(恢复) execution of a thread that was suspended(暂停,延缓) by the SuspendThread member function, or a thread created with the

CREATE_SUSPENDED flag. The suspend count of the current thread is reduced by one. If the suspend count is reduced to zero, the thread resumes execution; otherwise the thread remains suspended.

4)创建辅助线程事例:

UINT MyThreadProc( LPVOID pParam ) {

CMyObject* pObject = (CMyObject*)pParam; if (pObject == NULL ||

!pObject->IsKindOf(RUNTIME_CLASS(CMyObject))) return 1; // if pObject is not valid // do something with 'pObject'

return 0; // thread completed successfully }

// inside a different function in the program ...

pNewObject = new CMyObject;

AfxBeginThread(MyThreadProc, pNewObject);

3,主线程 和 辅助线程 的通话:(这里的主线程指应用程序,是个用户界面线程)

1)最简单的方法:使用全局变量。

(注意:如书上事例B中在一个辅助线程中使用全局的计数器,不希望其它现在在计数器递增的时候由于其它线程访问而引起混乱,则将起声明成volatile变量保证计数器不被保存到寄存器中,也可以使用InterlockedIncrement来阻塞其它线程同时使计数器递增。)

补充一:

InterlockedIncrement LONG InterlockedIncrement(

LPLONG lpAddend // pointer to the variable to increment );

//The InterlockedIncrement function both increments (increases by one) the value of the specified 32-bit variable and checks the resulting value. The function prevents more than one thread from using the same variable simultaneously.

补充二:

VC++技术内幕(windows编程篇)(17).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/592946.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)