When shut down all S7partner connections with Par_Stop() from a C# application, the application hangs sometimes.
Attaching WinDbg to the process shows that the lock is held in unmanaged code and the thread acquired the lock is dead.
Result !CS in WinDbg:
CritSec ntdll!LdrpLoaderLock+0 at 772820c0
WaiterWoken No
LockCount 12
RecursionCount 1
OwningThread 17e4
EntryCount 0
ContentionCount 95
Due to this blog https://blogs.msdn.microsoft.com/oldnewthing/20140808-00/?p=293 this situation can occur when a thread is canceled when holding a lock with TerminateThread. So I tried to increase all timeouts on WaitForSingleObject() to one minute to avoid the situation where TerminateThread is called. After this change my application did not hang anymore.
Is it possible to speed up the process of shut down the thread ?
Are there alternative ways to shut down the thread without the risk running into a deadlock ?
Thank you very much for any response !
Best regards,
Thomas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
the threads are closed setting to true the "terminated" var to allow a "natural" termination.
Sometime (connections hanged) the thread must be terminated to avoid an endless wait.
If you found 1 min as a reasonable time ok, I will investigate ;)
Unlukily I don't know a "perfect" way to kill a thread, this is a annoying problem working with threads.
Dave
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thank you very much for your quick response and the grate library.
I try to understand the source of the timeout, maybe there are some issues with my setup.
Kind regards,
Thomas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Deadlock TerminateThread
When shut down all S7partner connections with Par_Stop() from a C# application, the application hangs sometimes.
Attaching WinDbg to the process shows that the lock is held in unmanaged code and the thread acquired the lock is dead.
Result !CS in WinDbg:
CritSec ntdll!LdrpLoaderLock+0 at 772820c0
WaiterWoken No
LockCount 12
RecursionCount 1
OwningThread 17e4
EntryCount 0
ContentionCount 95
DebugInfo = 0x77284380
Critical section = 0x772820c0 (ntdll!LdrpLoaderLock+0x0)
LOCKED
LockCount = 0xD
WaiterWoken = No
OwningThread = 0x000017e4
RecursionCount = 0x1
LockSemaphore = 0x254
SpinCount = 0x00000000
Due to this blog https://blogs.msdn.microsoft.com/oldnewthing/20140808-00/?p=293 this situation can occur when a thread is canceled when holding a lock with TerminateThread. So I tried to increase all timeouts on WaitForSingleObject() to one minute to avoid the situation where TerminateThread is called. After this change my application did not hang anymore.
Is it possible to speed up the process of shut down the thread ?
Are there alternative ways to shut down the thread without the risk running into a deadlock ?
Thank you very much for any response !
Best regards,
Thomas
Hi,
the threads are closed setting to true the "terminated" var to allow a "natural" termination.
Sometime (connections hanged) the thread must be terminated to avoid an endless wait.
If you found 1 min as a reasonable time ok, I will investigate ;)
Unlukily I don't know a "perfect" way to kill a thread, this is a annoying problem working with threads.
Dave
Hi Dave,
thank you very much for your quick response and the grate library.
I try to understand the source of the timeout, maybe there are some issues with my setup.
Kind regards,
Thomas