I myself am stuck in a really terrific problem. The code is as shown below.
class A
{
public:
A(){
m_event = CreateEvent(NULL, false, false, NULL);
m_thread = _beginthread(StaticThreadEntry, 0, this);
}
static void StaticThreadEntry(A * obj) { obj->ThreadEntry(); }
void ThreadEntry();
};
void A::ThreadEntry()
{
WaitforSingleObject(m_event,INFINITE);
}
int main()
{
A a;
SetEvent(m_event);
WaitForSingleObject(m_thread, INFINITE);
return 0;
}
Problem:
When the above code runs, sometimes (1 out of 5) it freezes and the control gets stuck in the WaitforSingleObject () call (inside the main function). The code always calls the SetEvent () function to ensure that the thread stops before the Wait () function is called.
I see no reason why he should ever hang?
source
share