windows系统调用 线程 启动与挂起
2014-06-11 10:48
295 查看
#include "iostream" #include "windows.h" using namespace std; class CWorkerThread{ public: CWorkerThread(LPCTSTR m_szName):m_szName(m_szName),m_hThread(INVALID_HANDLE_VALUE){ m_hThread=CreateThread( NULL, 0, ThreadProc, reinterpret_cast<LPVOID>(this), 0, NULL ); } virtual ~CWorkerThread(){CloseHandle(m_hThread);} virtual void WaitForCompletion(){ WaitForSingleObject(m_hThread,INFINITE); } virtual void SetPriority(int nPriority){ SetThreadPriority(m_hThread,nPriority); } virtual void Suspend(){ SuspendThread(m_hThread); } virtual void Resume(){ ResumeThread(m_hThread); } protected: static DWORD WINAPI ThreadProc(LPVOID lpParam){ CWorkerThread *pThis= reinterpret_cast<CWorkerThread*>(lpParam); pThis->DoStuff(); return (0); } virtual void DoStuff(){ for(int n=0;n<10;n++){ cout<<"Thread"<<m_szName<<"ID:"<<GetCurrentThreadId()<<",count"<<n<<endl; } } protected: HANDLE m_hThread; LPCTSTR m_szName; }; void main(){ CWorkerThread wtA("A"); CWorkerThread wtB("B"); wtA.SetPriority(THREAD_PRIORITY_LOWEST); wtB.Suspend(); wtA.WaitForCompletion(); wtB.Resume(); wtB.WaitForCompletion(); cout<<"Both threads complete."<<endl; getchar(); }
相关文章推荐
- 浏览器调用windows系统exe文件方法可以用于启动屏幕键盘等功能哦
- WINDOWS系统启动过程中是如何调用硬盘数据的?
- windows系统调用 线程创建
- Linux和Windows系统调用的比较图
- 跨线程调用Windows窗体控件
- 剖析Windows系统服务调用机制
- Gloomy对Windows内核的分析(系统调用接口)
- 剖析Windows系统服务调用机制
- 设置Windows Vista系统启动时自动登录
- 剖析Windows系统服务调用机制
- Windows NT/2000系统中如何获取系统的启动时间(zz)
- Windows 系统调用.COM.微软语言引擎简单应用(C#)
- 调用Windows系统对话框
- windows 系统调用.WinAPI.直接绘制屏幕的应用.实列.CS屏幕中心点作弊器(1.6匪徒连狙专用)
- windows 系统调用.Windows索引服务.实列在Web访问索引服务
- How Do Windows NT System Calls REALLY Work?--Windows NT的系统调用究竟是如何工作的?
- Windows 系统编程初探 (五)结构化异常处理之二:线程相关异常处理
- 剖析Windows系统服务调用机制
- 使用windows系统调用编写shellcode
- pSOS&Win32--系统调用封装-任务管理(2): 开始 重起 挂起