"No problem using snprintf() in multiple threads."
Not true.
Not true, at least in the case of POSIX functions.
All the standard vararg functions vararg not mt-safe - this includes all the printf() family (1), but also any other variadic (2) function
sprintf() for example: "MT-Safe locale | AS-Unsafe heap | AC-Unsafe mem" - which means that it can fail if the locale is set asynchronously or if asynchronous thread cancellation is used, in other words, when using Such features in the MT environment should be given special attention.
va_arg not safe mt: | MT-Safe race: ap | AS-Safe | AC-Unsafe corrupt | - which means that an interlock is required.
In addition, which should be obvious, even a fully mt-safe function can be used in an unsafe way - what happens, for example, if two or more threads work with the same data / memory areas.
vtomazzi
source share