I have an application in which I suspect the Debugger has suspended a newly created thread and then occassionally fails to resume it.
The error happens in our custom TCP dll. I haven't been able to reproduce it in a simpler example, but I could make a simple tester that uses our library and sent it, with the library code, to someone. The library is faily small.
On a "connect" function call, the library creates two threads. Both are created without errors, but occassionally the thread created first, MonitorConnection, never runs. The 2nd thread waits on some things that the first thread is suppposed to be doing and, as a result, ends up in an infinite wait. (or failing on timed waits).
The problem goes away if the library is compiled in release mode which is why I suspect the debugger.(??)
I can also "fix" the problem by creating an Event (Windows Synchronization object) before I create the "MonitorConnection" thread. I then set the Event at the start of the MonitorConnection thread and wait on the Event after creating the thread. While this works, I can't do this every time I create a thread and would like to know why or when this error might pop up.
The following lines of code show what I've described. If I uncomment the WaitForSingleObject, the MonitorConnection thread does start. As is, the MonitorConnection thread.. sometimes (about 1 in 6)... never runs. I get the same result using CVI's Cmt Tread Functions vs the native SDK. Keep in mind that the thread is created ok, it just never runs (at all, does not execute it's first line of code).
>>> <<<<<
mon_info->event_thread_start = CreateEvent(NULL,1,0, "");
thread_hnd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MonitorConnection, (void*)mon_info, 0, &(mon_info->thread_id));
if(thread_hnd == NULL){
DebugPrintf("Create MonitorConnection failed\n");
}
/*result = WaitForSingleObject(mon_info->event_thread_start, 1000);
if(result != WAIT_OBJECT_0){
DebugPrintf(">>>>>>>>>>ERROR: Thread didn't start\n");
//...clean up
return -4;
}*/
if(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SpawnDataReadyCallback, (void*)mon_info, 0, &(mon_info->app_call_thread_id)) == NULL){
DebugPrintf("Create SpawnDataReadyCallback failed\n");
}