我有一个 C++ 代码,里面有两个线程。在线程 2 中的事件“A”之后,线程 1 应该暂停(挂起),线程 2 中将执行更多任务(例如事件“B”),最后线程 1 应该恢复。有没有办法做到这一点?
我的代码看起来像这样:
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;
}