[AGENT++] uxsnmp

Straus, Richard Richard.Straus at nuance.com
Wed May 13 16:18:44 CEST 2015


Hi Frank,

Order of our operations is as follows:

1. Call a 'Terminate' external function in the DLL from the client.
2. Terminate() involves:
	a) calling Snmp::stop_poll_thread()
	b) deleting the Snmp and v3MP instances
	c) calling Snmp::socket_cleanup()
3. Client unloads DLL after Terminate() completes.

The problem was caused by the m_hThreadEvent signaling the completion of the worker thread when in fact it hadn't yet closed. The key is to ensure the thread exits before stop_poll_thread exits. This is guaranteed by having WaitForSingleObject wait on the thread handle itself which is signaled when the thread exits.



Richard Straus


-----Original Message-----
From: AGENTPP [mailto:agentpp-bounces at agentpp.org] On Behalf Of Frank Fock
Sent: May-12-15 6:09 PM
To: agentpp at agentpp.org
Subject: Re: [AGENT++] uxsnmp

Hi Richard,

Wouldn't it be better to have a callback when the thread ended and then unload the DLL.
Your workaround might be working but I do not see a reason why that should prevent a crash for sure. A race condition may still occur, doesn't it?

Best regards,
Frank

Am 07.05.2015 um 17:05 schrieb Straus, Richard:
> Hi,
>
> We have encountered a crash in the Snmp::stop_poll_thread() call. This crash includes the latest version of snmp++ 3.3.5.
>
> We have determined the issue to be caused by WaitForSingleObject call:
>
> #ifdef WIN32
>      ::WaitForSingleObject(m_hThreadEndEvent, INFINITE);
>      CloseHandle(m_hThread);
>
> The SNMP calls are made in a DLL that is loaded and then unloaded. The problem is the thread keeps running for a brief period of time after setting m_hThreadEndEvent and during that time, the DLL unload sometimes completes - taking away the object code from the still-executing thread.
>
> We have been able to resolve the issue for WIN32 by removing all code referring to m_hThreadEndEvent. That means deleting the CreateEvent, SetEvent, ResetEvent calls pertaining to m_hThreadEndEvent as they are unnecessary. The above code in stop_poll_thread() is then replaced with this code:
>
> #ifdef WIN32
>                  if (NULL != m_hThread && INVALID_HANDLE_VALUE != m_hThread)
>                  {
>                                  ::WaitForSingleObject(m_hThread, INFINITE);
>                                  CloseHandle(m_hThread);
>                                  m_hThread = NULL;
>                  }
>
> Regards
>
> Richard Straus
> Senior Software Developer
> Equitrac MFP and Print Management Solutions Nuance Communications
>
> _______________________________________________
> AGENTPP mailing list
> AGENTPP at agentpp.org
> https://oosnmp.net/mailman/listinfo/agentpp

--
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231

_______________________________________________
AGENTPP mailing list
AGENTPP at agentpp.org
https://oosnmp.net/mailman/listinfo/agentpp


More information about the AGENTPP mailing list