Home > Software engineering >  Consult everybody a callback function
Consult everybody a callback function

Time:10-11

Recently wrote a program using a timer to create another thread every two seconds to perform some things, within the callback function is how to share data in a class? Some statements I want it only in the callback function can perform it again, please do?

CodePudding user response:

Implement several interface function in the class,

CodePudding user response:

Passing the class pointer as a function parameters, such as in the past

CodePudding user response:

The function is called different threads, they belong to different threads, as long as it is, you must ensure that synchronization, using the simplest critical region synchronization

CodePudding user response:

To the relevant parameters as the callback function, or do you define a global or static members, the callback function can access to the can,

CodePudding user response:

Shared data as long as the data set to global variables, parameters can also be
Only once can set a global variable
Such as
 
Int tis=0;//define a global variable
If (tis==0)
{
//do you want to execute statements
Tis++;
}//in the callback function

CodePudding user response:

The incoming class pointer, the static or global object

CodePudding user response:


1
2
3
4
5
6
7
8
9
10
11.
12
13
14
15
16
Void CCashUnitAgeTestDlg: : OnOK ()
{
AfxBeginThread (ProcRunThread, (LPVOID) this);//the incoming object pointer
}

Void CCashUnitAgeTestDlg: : vShowResult (LPCTSTR p_pcTestInfo)
{
.
}

UINT ProcRunThread (LPVOID pParam)
{
//conversion
PParam CCashUnitAgeTestDlg * pDlg=(CCashUnitAgeTestDlg *);
PDlg - & gt; VShowResult ()
}
  • Related