问题在Visual Studio的Win32环境中仍然存在。我有2个班级:
void classA::DoSth(HWND param){
for(int i = 0; i<24; i++)
std::cout<<i<<"\n";
}
void classB::DataGood(HWND param){
std::cout<<"OKAY\n";
}
示例文件:Implement.cpp
UINT startDAQThread(LPVOID param)
{
theApp.myClassB = new ClassB; //reference to theApp found below
theApp.myClassB->DataGood((HWND)param); //continually looks for data
return(0);
}
UINT startAlgorithmThread(LPVOID param)
{
theApp.classAPtr->DoSth((HWND)param);
return(0);
}
BOOL Implementation::OnInitDialog(){
AfxBeginThread(startDAQThread, GetSafeHwnd(), THREAD_PRIORITY_NORMAL);
Sleep(1000);
AfxBeginThread(startAlgorithmThread, GetSafeHwnd(), THREAD_PRIORITY_ABOVE_NORMAL);
return TRUE;// #define TRUE 1
}
MainApp.h
class MainApp:public CWinApp{
MainApp();
};
extern MainApp theApp;
MainApp.cpp
MainApp theApp;
[输出:
1
2
3
OKAY
4
5
OKAY
6
7
8
OKAY
9-23
如何确保循环先完成其运行,然后再执行其他一些执行?
我完成的研究:
作为初学者,我确实做了一些努力来尝试添加互斥锁并限制资源共享。我没有成功,因为我无法弄清两个类/函数之间正在共享什么资源
我已确保包含所有#includes
,并且程序可以编译并运行