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服务的形式来让它能够自启动.今天遇到一个问题,当 ...
随机推荐
- 蓝牙的OBEX协议
1.概述 OBEX为Object Exchange,用于在蓝牙设备间传数据对象,来源于红外定义的协议,后被蓝牙采用.OBEX在蓝牙协议层中的位置如下图(在之前的OBEX版本中,OBEX是通过R ...
- C++内存问题大集合(指针问题,以及字符串拷贝问题,确实挺危险的)
作者:rendao.org,版权声明,转载必须征得同意. 内存越界,变量被篡改 memset时长度参数超出了数组长度,但memset当时并不会报错,而是操作了不应该操作的内存,导致变量被无端篡改 还可 ...
- [LeetCode] Letter Combinations of a Phone Number(bfs)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- NSURLConnection同步与异步请求 问题
NSURLConnection目前有两个异步请求方法,异步请求中其中一个是代理.一个同步方法.有前辈已经详细介绍,见:http://blog.csdn.net/xyz_lmn/article/deta ...
- cf708B. Recover the String---(构造法)
题目链接:http://codeforces.com/problemset/problem/708/B 意思是给出四个参数 a00表01串中00对的数量 a01表01串中01对的数量 a10表01串中 ...
- A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.
图解: 此题过程分为三个阶段,分别是 1.负责后面一个节点,并且将这个节点插入到原来链表中 2.复制后面一个节点的random指针. 3 拆分组合链表为两部分. 第一部分代码: while(curr ...
- c#中的linq一
c#中的linq 测试数据: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- 微信公众平台开发(84) 小i机器人
很多朋友询问如何开发小黄鸡之类的智能聊天机器人,但遗憾的是小黄鸡接口申请页面在最近几个月里都无法访问,且使用时限制太大,我们找了另一个接口:小i机器人.本文介绍如何在微信公众平台中使用小i接口开发智能 ...
- RabbitMQ学习总结 第一篇:理论篇
目录 RabbitMQ学习总结 第一篇:理论篇 RabbitMQ学习总结 第二篇:快速入门HelloWorld RabbitMQ学习总结 第三篇:工作队列Work Queue RabbitMQ学习总结 ...
- 详解Java中的clone方法:原型模式
转:http://developer.51cto.com/art/201506/478985.htm clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的 ...