[AGENT++] Crash in multi-threaded SNMP++ use (usm_v3.cpp:1262)

John McCaskey jmccaskey at gmail.com
Fri Mar 17 01:30:11 CET 2006


Hi all,

Attached is a patch file against snmp++ 3.2.20 which modifies v3MP to not be
a singleton.  The appropriate usage is then to create a new v3MP as you
would normall, but now you need to pass the pointer to it as the second
argument to your Snmp() session constructor.  I also removed the v3 locking,
as the idea is now there can be true thread independance and safety if you
create one v3MP object per thread.

I truly believe that this is a better way to do threading in SNMP++ as it
will allow avoiding all of the issues that have come up in this thread all
together, but it will cause some backwards compatibility headaches for
users.  I haven't updated any of the examples or looked at the Agent++ code
so I don't know what impact these changes will have on either of those.
However, if anyone is interested in it, here it is!

Here is an example of how I'm using it:

// Wrapper for some SNMP++ objects to ease the interface with my other app
logic
struct SNMPSession {
    Snmp *snmp;
    SnmpTarget *target;
    Pdu pdu;
    v3MP *v3_MP;
};

// TSS is a template class I've created that will allocate thread specific
storage for
// the class specified (in this case v3MP) and will then allow us to easily
ensure this
// storage is just created once per thread, resused, and then deleted when
the
// thread ends
TSS<v3MP> tss;

// See if we already have a v3MP for this thread
session.v3_MP = tss.getData();
if(session.v3_MP == NULL) {
        // We don't have a v3MP for this thread, create it..
        LOG_MSG("We need a new v3MP for thread %lu", pthread_self());
        int construct_status;
        session.v3_MP = new v3MP("KlirPolling", 1, construct_status);
        assert(session.v3_MP);
        tss.setData(session.v3_MP);
}

UdpAddress address(device.snmp_polling_peername);
session.snmp = new Snmp(status, session.v3_MP, 0,(address.get_ip_version()
== Address::version_ipv6));
assert(session.snmp);

// At this point I continue on setting the various settings I need to make
// my snmp requests inside the session.snmp, session.target, and session.pdu
// objects  there is no need to delete the v3MP ever as that is handled by
the
// code in TSS which will call the thread specific storage destructor when a

// thread disappears in my case i have a constant pool of 80 threads, and
// then some one off threads on occaision, so I minimize overhead and only
// create 80 v3MP's ever, and then a few one offs now and then

I hope this is at least minorly helpful, I know Jochen mentioned perhaps
doing something along these lines and that making v3MP a non-singleton class
had been requested by others.  I have been using this code without issues
for several days now, but that is certainly not to say its bug free and
ready for production use! Use at your own risk!

John McCaskey
Sr. Software Development Engineeer
Klir Technologies, Inc.
johnm at klir.com

On 3/15/06, Jochen Katz <katz at agentpp.com> wrote:
>
> Hi all,
>
> only little tested fixed snmp++/agent++ versions can be downloaded from
> http://agentpp.org/~katzwww/snapshot/
> All needed info is in the CHANGES file.
>
> It's too late now for further testing...
> Good night,
>   Jochen
>
> _______________________________________________
> AGENTPP mailing list
> AGENTPP at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/agentpp
>


More information about the AGENTPP mailing list