我有一个C++代码,其中有两个线程。在线程2中的事件'A'之后,线程1应该暂停(挂起),线程2中要执行更多的任务(比如事件'B'),最后线程1应该被恢复。有没有办法做到这一点?暂停和恢复一个C++线程在另一个
我的代码看起来是这样的:
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;
}
你正在做的,现在,什么问题? – deepmax 2013-03-19 14:09:51
随机死锁,毫无疑问。 – 2013-03-19 14:56:56