Home > Software engineering >  VS2010 MFC threading issues
VS2010 MFC threading issues

Time:09-26

 
UINT CDiskSpeedDlg: : ZWrite (LPVOID lpParam)//thread 1
{
.
}
UINT ThreadProc (LPVOID Param)//thread 2
{
While (true)
{
Sleep (1000);
CProgressCtrl * Speed=(CProgressCtrl * Param);

If (Speed - & gt; GetPos ()==nUpper)
{
Speed - & gt; SetPos (nLower);
}
If (I % r!=0)
{
break;
}
If (I % r==0)
{
Speed - & gt; StepIt ();
}
}
return 0;
}


I want to keep thread 2 normally open the effect of every 1 second to perform a thread for execution and 1,
Interface effect
Thread 1 is continuing to output data, the edit box (completed)
Thread by thread 1 2 changes to the global variable (I) to determine whether I meet the execution conditions of thread 2, if meet, does not meet the exit, but 2 threads to every 1 second to judge a what should I do?? Very urgent! Me how to change the above code should be??
Don't use the mutex or semaphore, if use what should I change

CodePudding user response:

Is to make the thread 2 every 1 seconds once, what should I do

CodePudding user response:

The first step is to open a thread to judge whether meet the conditions, does not meet the thread exits
Second, wait a second thread, open another judgment
Waiting for a second open thread again,,,,,,,,,,,,,,,,, how should I change??

CodePudding user response:

CRITICAL_SECTION m_CS;
InitializeCriticalSection (& amp; M_CS);
DeleteCriticalSection (& amp; M_CS);

The EnterCriticalSection (& amp; M_CS);
The operation I
LeaveCriticalSection (& amp; M_CS);

CodePudding user response:

Directly with a timer, cycle for 1 second

CodePudding user response:

In the thread control is a dangerous operation, ThreadProc has a problem, use a timer
  • Related