CCriticalSection施用//为啥下面没输出呢?
CCriticalSection使用//为啥下面没输出呢?????
// ccc.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "ccc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 唯一的应用程序对象
CWinApp theApp;
CCriticalSection keyh264;
CWinThread* m_pThreadR;
CWinThread* m_pThreadW;
using namespace std;
char stack[6]="";
int size=0;
int off = true;
void Print(){
int i;
for(i=0;i<size;i++)
cout<<stack[i]<<' ';
cout<<"\n";
}
static UINT InputProc( LPVOID pParam ){
keyh264.Lock();
for(int i=0;i<81;i++)
{
while(size==6)
{
//goto end;
}
stack[size]=i;
size++;
//cout<<"size="<<size<<endl;
}
off = false;
end:
keyh264.Unlock();
return 0;
}
static UINT PrintProc( LPVOID pParam ){
keyh264.Lock();
while(off) {
while(size == 0)
{
//goto end;
}
Print();
size--;
}
end:
keyh264.Unlock();
return 0;
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("错误: MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
// TODO: 在此处为应用程序的行为编写代码。
m_pThreadR = AfxBeginThread(PrintProc,NULL,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
m_pThreadW = AfxBeginThread(InputProc,NULL,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
HANDLE hThread[2] = {m_pThreadR->m_hThread,m_pThreadW->m_hThread};
m_pThreadR->ResumeThread();
m_pThreadW->ResumeThread();
WaitForMultipleObjects( 2, hThread, TRUE, INFINITE );
CloseHandle( hThread[0] );
CloseHandle( hThread[1] );
}
return nRetCode;
}
文章评论
相关解决方案