Home > Software engineering >  In the MFC AfxBeginThread how to end this thread to release resources?
In the MFC AfxBeginThread how to end this thread to release resources?

Time:10-21

The code is as follows:
 void CMyFristDlg: : OnBnClickedButton13 () 
{
Int arg c=1;
Char * argv []={" OpenGL Thread "};
GlutInit (& amp; Arg c, argv);//initialize the glut
The UpdateData (TRUE);
CWinThread * Mythread=new CWinThread ();
Mythread=AfxBeginThread (AFX_THREADPROC OpenGLThread1, this);//create the opengl thread
The UpdateData (FALSE);
}
Int CMyFristDlg: : OpenGLThread1 (LPVOID LPV)
{
CMyFristDlg * pTaskMain=(CMyFristDlg *) LPV;
ScreenW=glutGet (GLUT_SCREEN_WIDTH);
ScreenH=glutGet (GLUT_SCREEN_HEIGHT);
Int windowPosX=0;
Int windowPosY=0;
GlutInitWindowPosition (windowPosX windowPosY);
GlutInitWindowSize (WINDOW_SIZE_W WINDOW_SIZE_H);
If (stereoMode==C_STEREO_ACTIVE)
GlutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STEREO);
The else
GlutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
GlutCreateWindow (" gall bladder pressure ");

# ifdef GLEW_VERSION
//initialize GLEW
GlewInit ();
# endif
GlutMouseFunc (mouseClick);
GlutMotionFunc (mouseMove);
GlutDisplayFunc (updateGraphics);
GlutKeyboardFunc (keySelect);
GlutReshapeFunc (resizeWindow);
Mydisplay ();
//create a thread which starts the main haptics rendering loop
CThread * hapticsThread=new cThread ();
HapticsThread - & gt; Start (updateHaptics CTHREAD_PRIORITY_HAPTICS);
//simulationRunning=false;
//setup a callback when the application exits
Atexit (close);
//start the main graphics rendering loop
GlutTimerFunc (50, graphicsTimer, 0);
GlutSetOption (GLUT_ACTION_ON_WINDOW_CLOSE GLUT_ACTION_GLUTMAINLOOP_RETURNS);
GlutMainLoop ();
return 0;
}

CodePudding user response:

"Windows core programming?"

CodePudding user response:

AfxBeginThread is a function of starting a thread,

To end a thread or thread after the completion of the task, such as their end,
And Windows news, notice it end,
There is violence AfxEndThread ends or other forced termination API,
But will bring the problem of memory leaks,

"A simple MFC" can refer to J.J.H OU

CodePudding user response:

By the thread to release their own resources

CodePudding user response:

I was like this:

In the thread function:
While (flag)
{
.
}

Want to end thread function, called the mutual function of the thread class, the flag set to false

CodePudding user response:

You of the thread, let it be, thread end of the run, natural resources is released,
  • Related