[AGENT++] MT-safety of get_printable() (was: SNMP++ advocacy)

Don Radick dradick at mindspring.com
Sat Jan 15 01:32:20 CET 2005


On Fri, 2005-01-14 at 10:42 +0100, maom_onet at poczta.onet.pl wrote:
> Użytkownik Don Radick <dradick at mindspring.com> napisał:
> >On Wed, 2005-01-12 at 23:35 +0100, maom_onet at poczta.onet.pl wrote:
> >> A possible approach would be:
> >> 
> >> if (addr_changed)
> >> {
> >>    char buf[LARGE_ENOUGH];
> >>    format_output(buf);
> >>    strcpy(output_buffer, buf);
> >>    addr_changed = false;
> >> }
> >> return output_buffer;
> >> 
> >> There is some overhead but this guarantees "strong MT-safety".
> >> 
> >
> >Not unless strcpy is an atomic operation.
> >During the cycles for the strcpy, the output_buf[] is invalid.
> >You\'ll need to use a critical section, a semaphore, or a MT-safe strcpy.
> 
> If strcpy() is implemented in such a way:
> 
> while (*s1++ = *s2++)
>     ;
> 
> then, where is the problem? I assume that the buffer will not be returned before one of (possible multiple) strcpy() is finished.
> 
> Marek

You are correct.  I was continuing to think in MT terms. and your
solution will simply require the other thread to wait on the buffer
copy.

-Don




More information about the AGENTPP mailing list