[AGENT++] Threading problem

Eggers, Henning Henning.Eggers at plath.de
Tue Jan 16 11:13:52 CET 2007


Hi,
I am posting this for a colleague who is not on the list (and does not do much SNMP anyway).
Cheers,
Henning


Our AgentX subagent implementation was having problems when no master agent is present. This being a WIN32 (VC6) build, it was eating handles each time it tried to reconnect to the master. I traced the problem to the Thread class and propose the following changes to resolve this problem:

1. Before Thread starts a new thread it should check if the Handle is not possibly already open. This is accomplished by setting thread_handle to a definite value in the constructor (INVALID_HANDLE_VALUE) and checking for it before creating a new thread instance.

2. Less related to this problem is an issue I discoverd earlier in other projects. Using WaitForSingleObject on thread_handle to implement a join() operation has only proven to be 80% successful. In the remaining cases WaitForSingleObject missed the termination of the thread and kept waiting for ever. Using an extra Event to indicate that the thread has ended works fine, though.
I therefore added an Event called threadEndEvent which is created by thread_starter and waited for by the join() method.

I attached the edited files "threads.h" and "threads.cpp" from Agent++ 3.5.27b that implement my proposals. I do not have a diff program handy to generate a proper patch.

Best Regards,
Frank Kähler
Plath GmbH


More information about the AGENTPP mailing list