Semaphore内核对象的使用
来源:互联网 发布:周立功单片机 招聘 编辑:程序博客网 时间:2024/06/05 16:54
Semaphore内核对象的使用
// Semaphore.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <Windows.h>#include <process.h> HANDLE g_hSemaphore;DWORD g_nConut1 = 0;DWORD g_nConut2 = 0;unsigned __stdcall ThreadProc1( void* pArguments ){::WaitForSingleObject(g_hSemaphore, INFINITE);for (int i=0;i<10000;i++){g_nConut1++;g_nConut2++;}::ReleaseSemaphore(g_hSemaphore, 1, NULL);printf("ThreadProc1\n");return 0;}unsigned __stdcall ThreadProc2( void* pArguments ){::WaitForSingleObject(g_hSemaphore, INFINITE);for (int i=0;i<10000;i++){g_nConut1++;g_nConut2++;}::ReleaseSemaphore(g_hSemaphore, 1, NULL);printf("ThreadProc2\n");return 0;}unsigned __stdcall ThreadProc3( void* pArguments ){::WaitForSingleObject(g_hSemaphore, INFINITE);for (int i=0;i<10000;i++){g_nConut1++;g_nConut2++;}::ReleaseSemaphore(g_hSemaphore, 1, NULL);printf("ThreadProc3\n");return 0;}int _tmain(int argc, _TCHAR* argv[]){g_hSemaphore = ::CreateSemaphore(NULL, 2, 2, NULL);HANDLE hThread[3];hThread[0] = (HANDLE)::_beginthreadex(NULL, 0, ThreadProc1, NULL, 0, NULL);hThread[1] = (HANDLE)::_beginthreadex(NULL, 0, ThreadProc2, NULL, 0, NULL);hThread[2] = (HANDLE)::_beginthreadex(NULL, 0, ThreadProc3, NULL, 0, NULL);::WaitForMultipleObjects(2,hThread,TRUE, INFINITE);printf("g_count1=%d\n", g_nConut1);printf("g_count2=%d\n", g_nConut2);printf("main finished.\n");return 0;}
- Semaphore内核对象的使用
- 线程同步 信号量 Semaphore 内核对象 CreateSemaphore
- semaphore信号的使用
- Semaphore(信号量)的使用
- Semaphore的使用
- Semaphore信号量的使用
- Semaphore信号量的使用
- Semaphore的使用
- SemaPhore的使用
- Semaphore的使用
- Linux 内核的同步机制--semaphore, rw_semaphore
- signal、semaphore机制在Linux内核和System V的IPC中使用的区别
- -内核对象的使用计数
- 互斥量内核对象的使用
- Windows进程同步之信号量内核对象(Semaphore)
- Windows进程同步之信号量内核对象(Semaphore)
- 信号量 Semaphore的使用介绍
- java并发:Semaphore 的使用
- OLEDB与ADO 、ADO.NET
- HR相关表
- Google drive 安装
- ASP.NET跨页提交和表单提交
- jquerymobile局部渲染的各种刷新
- Semaphore内核对象的使用
- 常用正则表达式汇总
- Libnids---编写网络应用程序的利器
- Ubuntu 下date 的用法和时间格式
- DataGrid控件用法详解
- 什么是可重入函数和不可重入函数(转)
- Spring2.5_Reference阅读笔记——001——搭建环境,实现IOC
- 职称 PM,PL,SE,PG 的意思
- MySQL错误代码中文说明