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

maom_onet at poczta.onet.pl maom_onet at poczta.onet.pl
Fri Jan 14 10:42:41 CET 2005


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



More information about the AGENTPP mailing list