Is Net-SNMP thread safe?
Strictly speaking, no. However, it is possible to use the library within a multi-threaded management application. This is covered in detail in the file README.thread (shipped with the standard distribution), but can be summarised as follows:
- Call 'snmp_sess_init()' prior to activating any threads.
This reads in and parses MIB information (which isn't thread-safe) as well as preparing a session structure for subsequent use.
- Open an SNMP session using 'snmp_sess_open()' which returns an opaque session handle, which is essentially independent of any other sessions (regardless of thread).
- Resource locking is not handled within the library, and is the responsibility of the main application.
The Net-SNMP agent has not been designed for multi-threaded use. It should be safe to use the agent library to embed a subagent within a threaded application as long as *all* SNMP-related activity (including generating traps, and parsing MIBs) is handled within a single thread.
The command-line tools shipped as part of the Net-SNMP distribution
are simple single-threaded applications, and are not designed for
multi-threaded use. Adapting these to a threaded model is left as
an exercise for the student.
The same holds true for the notification receiver (snmptrapd).
Unfortunately, the SNMPv3 support was added about the same time as the thread support and since they occurred in parallel the SNMPv3 support was never checked for multi-threading correctness. It is most likely that it is not thread-safe at this time.
- What is it?
- Where can I get it?
- What documentation is available?
- Are there binaries available?
- What's the difference between UCD-SNMP and Net-SNMP?
- What operating systems does it run on?
- What happens if mine isn't listed?
- Does it run on Windows?
- How do I find out about new releases?
- How can I find out what other people are doing?
- How do I submit a patch or bug report?
- Can I reuse the code in my commercial application?
- What's the difference between SNMPv1, SNMPv2 and SNMPv3?
What's the difference between SNMPv2 and SNMPv2c?
- Which versions of SNMP are supported in this package?
- Can I use SNMPv1 requests with an SNMPv2 MIB (or vice versa)?
- How can I monitor my system with SNMP?
- Where can I find more information about network management?
- What ports does SNMP use?
- Is Net-SNMP thread safe?