windows系统调用 临界区机制
#include "iostream"
#include "windows.h"
#include "cstring"
using namespace std; static int g_nIndex=;
const int MAX_TIMES=;
static DWORD g_dwTimes;
CRITICAL_SECTION g_CriticalSection; DWORD WINAPI IncProc(LPVOID lpParam){
BOOL fDone=FALSE;
while(!fDone){
EnterCriticalSection(&g_CriticalSection);
if(g_nIndex>=MAX_TIMES){
fDone=TRUE; }
else{
g_dwTimes++;
printf("The Inc count's value is%d.\n",g_dwTimes);
g_nIndex++;
Sleep();
}
LeaveCriticalSection(&g_CriticalSection);
} return();
} DWORD WINAPI DecProc(LPVOID lpParam){
BOOL fDone=FALSE;
while(!fDone){
EnterCriticalSection(&g_CriticalSection);
if(g_nIndex>=MAX_TIMES){
fDone=TRUE;
}
else{
g_dwTimes--;
printf("The Dec count's value id %d.\n",g_dwTimes);
g_nIndex++;
Sleep();
}
LeaveCriticalSection(&g_CriticalSection);
} return();
} void main(){
HANDLE hThread[]; InitializeCriticalSection(&g_CriticalSection); hThread[]=CreateThread(
NULL,
,
IncProc,
reinterpret_cast<LPVOID>(),
,
NULL
);
printf("Thread0 is Created!\n"); hThread[]=CreateThread(
NULL,
,
DecProc,
reinterpret_cast<LPVOID>(),
,
NULL
);
printf("Thread1 is Created!\n"); printf("Both Threads are ready into critical section!\n"); WaitForMultipleObjects(,hThread,TRUE,INFINITE); CloseHandle(hThread[]);
CloseHandle(hThread[]); DeleteCriticalSection(&g_CriticalSection); getchar();
}
windows系统调用 临界区机制的更多相关文章
- Windows系统调用架构分析—也谈KiFastCallEntry函数地址的获取
为什么要写这篇文章 1. 因为最近在学习<软件调试>这本书,看到书中的某个调试历程中讲了Windows的系统调用的实现机制,其中讲到了从Ring3跳转到Ring0之后直接进入了K ...
- 全面介绍Windows内存管理机制及C++内存分配实例
转自:http://blog.csdn.net/yeming81/article/details/2046193 本文基本上是windows via c/c++上的内容,笔记做得不错.. 本文背景: ...
- windows程序消息机制(Winform界面更新有关)
windows程序消息机制(Winform界面更新有关) 转自:http://www.cnblogs.com/blosaa/archive/2013/05/31/3109586.html 1. Win ...
- windows程序消息机制(Winform界面更新有关)--转
1. Windows程序消息机制 Windows GUI程序是基于消息机制的,有个主线程维护着消息泵.这个消息泵让windows程序生生不息. Windows程序有个消息队列,窗体上的所有消息是这个队 ...
- 深入详解windows安全认证机制ntlm&Kerberos
0x01 为什么要理解windows 安全认证机制: 加深对后续各种漏洞利用的理解深度,还是那句话,要知其然,更要知其所以然,不废话,咱们直接开始 0x02 windows认证协议主要有以下两种: 基 ...
- 全面介绍Windows内存管理机制及C++内存分配实例(四):内存映射文件
本文背景: 在编程中,很多Windows或C++的内存函数不知道有什么区别,更别谈有效使用:根本的原因是,没有清楚的理解操作系统的内存管理机制,本文企图通过简单的总结描述,结合实例来阐明这个机制. 本 ...
- Windows系统调用中的现场保存
Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html Windows系统调用中的现场保存 我们之前介绍过三环进零环的步骤 ...
- Windows系统调用中的系统服务表描述符
Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html Windows系统调用中的系统服务表描述符 在前面,我们将解过 ...
- Windows系统调用中API的3环部分(依据分析重写ReadProcessMemory函数)
Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html Windows系统调用中API的3环部分 一.R3环API分析的重 ...
随机推荐
- The Skins of the Substance
This blog is about a java jar file : Substance.jar well, you can get it from links as below: http:// ...
- vsfptd
如果想通过vsftpd来在主机和虚拟机之间拿数据,可以通过这种方法: 在主机的资源管理器中输入:ftp://虚拟机里面Linux的IP(如192.168.2.112)/ 如果反过来,需要如下:ftp: ...
- text-indent:-9999px 字体隐藏问题
为什么要字体隐藏? 通常为了传达更好的视觉效果,我们常用图片替代掉字体.但是为了html语义化,常常要给内容模块加上一些标题来让页面更有意义,在抛开css裸奔的情况下也能很顺利的汲取到页面信息.为此我 ...
- [LintCode] Nuts & Bolts Problem 螺栓螺母问题
Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping ...
- [zt]OJ常见的Judge Status
Queuing : 提交太多了,OJ无法在第一时间给所有提交以评判结果,后面提交的程序将暂时处于排队状态等待OJ的评判.不过这个过程一般不会很长. Compiling : 您提交的代码正在被编译. R ...
- oracle 学习摘录
(1)oracle插入回车换行符 SQL>insert into A t(t.name) values('aaaaa'||chr(10)||chr(13)||'ccccc'); 已创建 1 行. ...
- 导出所选行为excle
要实现的是将所选行导出.例如勾选这两条
- boostrap折叠,jquery ui accordion同时打开多个标签
http://caibaojian.com/bootstrap/javascript.html http://www.w3cschool.cc/jqueryui/example-accordion.h ...
- centos6 搭建ELK
mark一下时间:2016年2月19日10:17:09 记录使用 Logstash: Logstash服务的组件,用于处理传入的日志. Elasticsearch: 存储所有日志 Kibana 4: ...
- C# 特殊关键字
1.static 表示被修饰的对象的生命周期与当前的应用程序域相同,因此可以在多个实例中共享 2.const 表示常量且只能在声明时赋值,因此const的常量在编译时就能确定,它如果没有被static ...