[AGENT++] SNMP++ advocacy

Marek Malowidzki maom_onet at poczta.onet.pl
Wed Jan 12 10:56:27 CET 2005


Hi Jochen,

From: "Jochen Katz" <katz at agentpp.com>
To: <agentpp at agentpp.org>
Sent: Monday, January 10, 2005 11:28 PM
Subject: Re: [AGENT++] SNMP++ advocacy
> yes, all const methods are ok, beside the get_printable() functions, as
> these modify internal buffers.

Yes, of course, I forgot about these ones.

However, however... get_printable() should be MT-safe for const (not
modified) objects, as long as two properties are met:

1.) the flag describing buffer content validity is set after the buffer has
been formatted (which should be natural)

2.) given that the object is not altered, and that a buffer is formatted,
re-formatting it should not alter its content. Other way speaking, if there
are two threads that format buffer in parallel (both observe the flag set to
false/0), the buffer's bytes set by a "slower" thread should not modify
buffer content set by a "faster" thread. For example, the buffer should not
be used to hold temporary content.

Unfortunately, I have just realized that 2.) is very difficult to assure.
For example, this is not evident that e.g. sprintf() functions cannot be
used in such a case; even if there is a single call. I think this is not
specified how exactly the function works (whether it outputs its content
immediately, byte-by-byte, in order, to the buffer, or does some tricks). It
would require using a separate (stack-allocated) buffer and then copy its
content (after formatting) to an object's state.

Well, I think that there are two options:
- call get_printable() just after an object has been created, to pre-format
its buffer and seal the state
- use locks to synchronize access

I think I will apply the second method but would like to hear your opinion -
are get_printable() calls lightweight or not (I know it depends on a class
and amount of formatting to do but how you would comment on a "general
case")?

Marek






More information about the AGENTPP mailing list