📄 test1.cpp
字号:
// test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "test1.h"
#include "..\cqueue.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;
typedef struct str_data
{
int a;
CString str;
}Data;
typedef CYQueueSyn<Data*> Queue;
unsigned int printout(void* lp)
{
Queue* myQueue = (Queue*)lp;
while(1)
{
Sleep(200);
try
{
Data* myData = (Data*)myQueue->outq();
printf("-----out %d %s\n", myData->a,myData->str);
delete myData;
}
catch(CYException & ye)
{
printf("---error %d,%s\n", ye.nError,ye.sMsg);
}
}
return 0;
}
/*
进栈
*/
unsigned int printin(void* lp)
{
Queue* myQueue = (Queue*)lp;
Data* myData = NULL;
int i =0;
CString stmp ;
while(1)
{
try
{
Sleep(3000);
myData = new Data;
myData->a = i++;
stmp.Format("%d", i);
myData->str = "test" + stmp;
myQueue->inq(myData);
}
catch(CYException & ye)
{
printf("%d,%s\n",ye.nError,ye.sMsg);
}
}
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
}
Queue myQueue(2,2000);
::AfxBeginThread(printout,&myQueue);
::AfxBeginThread(printin, &myQueue);
printf("step ...\n");
getchar();
return nRetCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -