What is Q:ccriticalsection?
A:ccriticalsection is a thread synchronization strategy or technique or method in short, that's what it means ....
Resources:
http://blog.csdn.net/akof1314/article/details/5773076
Http://www.cnblogs.com/hlxs/archive/2013/03/31/2991752.html
Http://baike.baidu.com/view/2471016.htm
First step: Open VS2010 to create a single document MFC program. and run OK to make sure the creation process
Step Two: Add a header file in the view header file # include "Afxmt.h"
And instantiate a CCriticalSection object in the implementation file of the view class.
Specifically, this object is not part of the view class, where it is defined as a global variable.
CCriticalSection gsz_criticalsection;
Step three: Define the two functions in the implementation file in the view. These two functions are brought back to be specified as thread functions. These two functions are not member functions of the view class.
UINT
AfxGetMainWnd function Gets the main frame class pointer in MFC program is a common practice of CWnd *pmainwnd = AfxGetMainWnd (); :: MessageBox (Pmainwnd->m_hwnd, PMessage, _t ("Thread message"), MB_OK); Gsz_criticalsection.unlock (); return 0; } UINT
AfxGetMainWnd function Gets the main frame class pointer in MFC program is a common practice
CWnd *pmainwnd = AfxGetMainWnd ();
}
Fourth step: Add the left mouse button message response function function to the view class is written as follows:
Note that this needs to be clicked as shown below to find a left-click response function.
void Ctestgszview::onlbuttondown (UINT nflags, CPoint Point)
{
TODO: Add Message Handler code and/or call default values here
AfxBeginThread (MessageThread1, _t ("Thread is Started")); Start thread 1
AfxBeginThread (MessageThread2, _t ("Thread is Started")); Start Thread 2
Cview::onlbuttondown (nflags, point);
}
Fifth step: Run the test.
Click the View area
There's the following stuff.
The use of ccriticalsection is actually demonstrated below MFC