麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

對于C++鎖的封裝及使用

2019-11-14 08:47:25
字體:
來源:轉載
供稿:網友
說明:文件名的GS前綴不代表任何含義      這里的鎖類暫時只支持windows平臺。GSMutex.h
#PRagma once#include <windows.h>#include <WinBase.h>class GSMutex{public:	GSMutex(void);	~GSMutex(void);	void	Lock();			//加鎖	void	Unlock();		//解鎖	bool	TryLock();		//true獲取鎖成功,false失敗private:	CRITICAL_SECTION m_hOS;};class GSAutoMutex{public:	GSAutoMutex(GSMutex& mutex);	~GSAutoMutex(void);private :	GSMutex& m_mutex;};GSMutex.cpp
#include "StdAfx.h"#include "GSMutex.h"GSMutex::GSMutex(void){	InitializeCriticalSection(&m_hOS);	}GSMutex::~GSMutex(void){	DeleteCriticalSection(&m_hOS);}void GSMutex::Lock(){	EnterCriticalSection(&m_hOS);}void GSMutex::Unlock(){	LeaveCriticalSection(&m_hOS);}bool GSMutex::TryLock(){	if (!TryEnterCriticalSection(&m_hOS))	{		return false;	}	return true;}GSAutoMutex::GSAutoMutex(GSMutex& mutex):m_mutex(mutex){	m_mutex.Lock();}GSAutoMutex::~GSAutoMutex(void){	m_mutex.Unlock();}LockTest.cpp
// LockTest.cpp : 定義控制臺應用程序的入口點。//#include "stdafx.h"#include <windows.h>#include <WinBase.h>#include <process.h>#include "GSMutex.h"GSMutex cs;unsigned int WINAPI ThreadFuncA(LPVOID lp){	GSAutoMutex csAuto(cs);	Sleep(3000);	printf("This is threadA/n");	return 0;}unsigned int WINAPI ThreadFuncB(LPVOID lp){	GSAutoMutex csAuto(cs);	printf("This is threadB/n");	return   0;}int _tmain(int argc, _TCHAR* argv[]){	HANDLE hThreadHandleArry[2];	memset(hThreadHandleArry, 0, sizeof(HANDLE)*2);	hThreadHandleArry[0] = (HANDLE)_beginthreadex(NULL, 0, ThreadFuncA, NULL, 0, 0);	hThreadHandleArry[1] = (HANDLE)_beginthreadex(NULL, 0, ThreadFuncB, NULL, 0, 0);		WaitForMultipleObjects(2, hThreadHandleArry, TRUE, INFINITE); 	for (int i = 0; i < 2; i++)	{		if (hThreadHandleArry[i] != NULL)		{			//關閉線程句柄,不會導致線程關閉			CloseHandle(hThreadHandleArry[i]);			hThreadHandleArry[i] = NULL;		}	}	system("pause");	return 0;}參考文章:http://blog.csdn.net/feixiaoxing/article/details/7017727
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 92自拍视频 | 精品久久中文字幕 | 国产一区网址 | 一级电影在线免费观看 | 黄色视频一级毛片 | 久久成人视屏 | 成人午夜在线免费观看 | 久久国产秒 | 中文字幕精品久久 | av影院在线 | 91精品国产91久久久 | 色交视频 | 亚洲成人自拍电影 | 高清国产福利 | 精品一区二区在线观看视频 | 99精品视频一区二区三区 | 亚洲一区二区不卡视频 | 色中色在线播放 | 亚洲成人中文字幕在线 | 激情综合网俺也去 | 模特三级在线观看 | 久久99久久98精品免观看软件 | 日本在线观看一区二区 | 一本色道久久综合亚洲精品小说 | a级毛片免费观看在线播放 日本aaa一级片 | 国产精品午夜未成人免费观看 | 国产在线精品91 | 亚洲第一视频 | 国产又白又嫩又紧又爽18p | 九九午夜 | xxxx hd videos| av影院在线播放 | 鲁人人人鲁人人鲁精品 | 免费一级毛片免费播放 | 亚洲一区二区三区高清 | 沉沦的校花奴性郑依婷c到失禁 | www中文在线 | 日本在线免费观看视频 | 久久国产精品久久久久 | 日韩欧美综合在线 | 97中文字幕第一一一页 |