Project Name: Multithread in Multithreadview - CPP
Project Name: Multithread in Multithreadview - CPP
In multithreadView.cpp
#include "stdafx.h"
#include "multithread.h"
#include "multithreadDoc.h"
#include "multithreadView.h"
#include "diathrd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CMultithreadView
IMPLEMENT_DYNCREATE(CMultithreadView, CView)
BEGIN_MESSAGE_MAP(CMultithreadView, CView)
//{{AFX_MSG_MAP(CMultithreadView)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW,
CView::OnFilePrintPreview)
END_MESSAGE_MAP()
// CMultithreadView construction/destruction
CMultithreadView::CMultithreadView()
{ }
CMultithreadView::~CMultithreadView()
{ }
// CMultithreadView drawing
// CMultithreadView printing
// CMultithreadView diagnostics
#ifdef _DEBUG
void CMultithreadView::AssertValid() const
{
CView::AssertValid();
}
#include "stdafx.h"
#include "multithread.h"
#include "diathrd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Cdiathrd dialog
int g_var=0;
void Cdiathrd::OnButton1()
{
CString str1;
int I , g_var=0;
CWinThread*
pThread=AfxBeginThread(ComputeThreadProc,GetSafeHwnd(),THREAD
_PRIORITY_NORMAL);
for(i=1;i<=5;i++)
{
::InterlockedIncrement((long*)&g_var);
str1.Format("Main g_var = %d",g_var);
MessageBox(str1);
try
{
Sleep(1000);
}
catch(CException e)
{}
}
}
OUTPUT