windows系统调用 线程 启动与挂起
#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系统调用 线程 启动与挂起的更多相关文章
- windows系统调用 线程创建
#include "windows.h" #include "iostream" using namespace std; class CWorkerThrea ...
- windows进程/线程创建过程 --- windows操作系统学习
有了之前的对进程和线程对象的学习的铺垫后,我们现在可以开始学习windows下的进程创建过程了,我将尝试着从源代码的层次来分析在windows下创建一个进程都要涉及到哪些步骤,都要涉及到哪些数据结构. ...
- 并发、线程的基本概念&线程启动结束
并发.进程.可执行程序.进程.线程的基本概念 1.并发 并发当有多个线程在操作时,如果系统只有一个CPU,则它根本不可能真正同时进行一个以上的线程,它只能把CPU运行时间划分成若干个时间段,再将时间段 ...
- C#线程篇---Windows调度线程准则(3)
Windows本身就是一个抢占式操作系统,它的实现,必定有某种算法在里面,比如什么时候调度哪些线程,需要花费多长时间等问题. 我们时时在用Windows,作为程序员,我们有必要知道其中最贴近我们的算法 ...
- Windows系统调用架构分析—也谈KiFastCallEntry函数地址的获取
为什么要写这篇文章 1. 因为最近在学习<软件调试>这本书,看到书中的某个调试历程中讲了Windows的系统调用的实现机制,其中讲到了从Ring3跳转到Ring0之后直接进入了K ...
- Windows系统调用中API从3环到0环(上)
Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html Windows系统调用中API从3环到0环(上) 如果对API在三 ...
- MFC 线程启动、暂停、继续、终止
CWinThread* p_myThread;//创建线程指针 BOOL flag_myThread = FALSE;//是否终止 //头文件中声明(放类内) static UINT MyThread ...
- Thread.start() ,它是怎么让线程启动的呢?
作者:小傅哥 博客:https://bugstack.cn Github:https://github.com/fuzhengwei/CodeGuide/wiki 沉淀.分享.成长,让自己和他人都能有 ...
- 当程序以Windows Services形式启动时当前路径不对
当程序以Windows Services形式启动时当前路径不对 @(操作系统)[博客|dotNet] 很多时候我们需要将我们的程序写成利用Windows服务的形式来让它能够自启动.今天遇到一个问题,当 ...
随机推荐
- Android 4.2蓝牙介绍
蓝牙一词源于公元十世纪丹麦国王HaraldBlatand名字中的Blatand.Blatand的英文之意就是Blue tooth.这是因为这位让丹麦人引以为傲的国王酷爱吃蓝莓以至于牙龈都被染成蓝色.由 ...
- UNION 查询中的排序
MSSQL 不允许在UNION查询中使用 ORDER BY 因此,当我们需要这种功能的时候,就需要绕一些弯路. 比如有一张学生表student 和教师表 teacher , 我们要查询所有的教师学生的 ...
- SqlServer中的一些非常用功能
1.启用双引号作为分隔符 Set Quoted_Identifier on 此时:create table dbo.testcolumn("column" char(2))是合法的 ...
- pushViewController addSubview presentModalViewController视图切换
1.pushViewController和popViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的, pushViewContro ...
- hadoop MapReduce 工作机制
摸索了将近一个月的hadoop , 在centos上配了一个伪分布式的环境,又折腾了一把hadoop eclipse plugin,最后终于实现了在windows上编写MapReduce程序,在cen ...
- magento 切换数据库,使用不同数据库
1. 在app/etc/local.xml 中,添加新的数据库选项 <?xml version="1.0"?> <config> <global> ...
- Emmet(之前叫Zencoding)插件安装
按 ctr+shift+P,输入 install Package,找到emmet,确认安装 Package Control Messages======================== Emmet ...
- 3d sphere opengl
http://stackoverflow.com/questions/5988686/creating-a-3d-sphere-in-opengl-using-visual-c
- CentOS设置虚拟网卡做NAT方式和Bridge方式桥接
CentOS设置虚拟网卡做NAT方式和Bridge方式桥接 http://www.centoscn.com/CentOS/config/2015/0225/4736.html 摘要:KVM虚拟机网络配 ...
- Encode & decode
1. 埃特巴什码 (Aitebashen Password) Definition: 最后一个字母代表第一个字母,倒数第二个字母代表第二个字母. 常文:a b c d e f g h i j k l ...