我有一段C++代码,其中包含两个线程。在第二个线程中发生事件'A'后,应暂停(挂起)第一个线程,某些其他任务需要在第二个线程中执行(例如事件'B'),最后要恢复第一个线程。有没有办法做到这一点?
我的代码大致如下:
HANDLE C;
DWORD WINAPI A (LPVOID in)
{
while(1){
// some operation
}
return 0;
}
DWORD WINAPI B (LPVOID in)
{
while(1){
//Event A occurs here
SuspendThread (C);
//Event B occurs here
ResumeThread (C);
}
return 0;
}
int main()
{
C = CreateThread (NULL, 0, A, NULL, 0, NULL);
CreateThread (NULL, 0, B, NULL, 0, NULL);
return 0;
}