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分析的重 ...
随机推荐
- Eclipse 使用maven创建Dynamic Web Project
今天看到spring的官网首页已经没有下载连接了,建议使用maven构建spring项目.虽然maven已经不是新技术,但是这个我还没用过,谷歌走起! 通常创建项目都是用Eclipse,前几年还是My ...
- PHP 解决nginx 用file_get_content 问题
$my_curl = curl_init(); //初始化一个curl对象 curl_setopt($my_curl, CURLOPT_URL, "http://www.webjoy.net ...
- SVN文本文件报二进制属性的问题
2011-11-21 00:42 svn总出现二进制相关的烦人事 在使用svn add 时提示: A (bin) templates/translate/screen/selectTransLan ...
- ORACLE 查看锁
SELECT object_name, machine, s.sid, s.serial# FROM gv$locked_object l, dba_objects o, gv$session s W ...
- Centos 安装 NodeJS
准备命令: yum -y install gcc make gcc-c++ openssl-devel wget 下载源码及解压: wget http://nodejs.org/dist/v0.10. ...
- Missing number
Missing number 题目: Description There is a permutation without two numbers in it, and now you know wh ...
- 用css3实现一个带缺口的圆圈(图)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JQuery的动画及其幻灯片效果
1.显示和隐藏hide()和show() 对于动画来说,显示和隐藏是最基本的效果之一,简单介绍jQuery的显示和隐藏. <script type="text/javascript&q ...
- spark reduce类操作
reduce类函数分析: ---------------------------------------------------------------------------- 待补全 ------ ...
- 安装redis时遇到zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
参考博文,http://www.phperz.com/article/14/1219/42002.html 解决办法 make MALLOC=libc