📄 queuedemo.cpp
字号:
// queueDemo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "queueDemo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
using namespace spBase;
CQueueAdmin glo_queue("test",2,4,1000);
DWORD TestThread(int iSeq)
{
int iTicket;
int iRet;
for(int i=0;i<2;i++)
{
iRet = glo_queue.EnterQueue(&iTicket);
if(iRet == QA_SUCCESS)
{
printf("thread %d EnterQueue ticket= %d\n",iSeq,iTicket);
Sleep(500);
printf("\tthread %d QuitQueue ticket= %d\n",iSeq,iTicket);
iRet = glo_queue.QuitQueue(iTicket);
printf("thread %d QuitQueue= %d\n",iSeq,iRet);
}
else
{
printf("thread %d EnterQueue= %d\n",iSeq,iRet);
Sleep(1000);
}
}
return 0;
}
void Test(void)
{
#define THREAD_NUM 10
HANDLE hT[THREAD_NUM];
for(int i=0;i<THREAD_NUM;i++)
{
DWORD dwID;
hT[i] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE )TestThread,(LPVOID)i,0,&dwID);
}
printf("wait all threads to quit\n");
WaitForMultipleObjects(THREAD_NUM,hT,TRUE,INFINITE);
printf("exit\n");
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
Test();
}
return nRetCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -