(Working in Win32 api , in C environment with VS2010)
I have a two thread app. The first thread forks the second and waits for a given interval - 'TIMEOUT', and then calls TerminateThread()
on it.
Meanwhile, second thread calls NetServerEnum()
.
It appears that when timeout is reached , whether NetServerEnum
returned successfully or not, the first thread get deadlocked.
I've already noticed that NetServerEnum
creates worker threads of it's own.
I ultimately end up with one of those threads in deadlock, typically on ntdll.dll!RtlInitializeExceptionChain
, unable to exit my process gracefully.
As this to too long for a comment:
Verbatim from MSDN, allow me to use te answer form (emphasis by me):
From reading this it is easy to understanf why it is a bad idea to cancel (terminate) a thread stucking in a system call.
A possible alternative approach to the OP's design might be to spawn off a thread calling
NetServerEnum()
and simply let it run until the system call returned.In the mean while the main thread could do other things like for example informing the user that scanning the net takes longer as expected.