Are va_list and vsnprintf "Thread-Safe"?

I have a relatively huge project (50+ source files, 10s of thousands of lines of code, over 260KByte object code, heavily interrupt-driven) that has a strange problem I suspect might be related to the fact that both foreground code and interrupt code use va_list/va_start/va_end and vsnprintf to format display data for an I2C LCD display. If I replace the call to the function that does that formatting and writing to the LCD with Serial.print, the problem does not occur.

It's been decades since I've looked at the source code for the va_ functions, or vsnprintf. Does anyone here knew if they are "thread-safe"? Is it possible the interrupt code is buggering the foreground code by calling those functions?

Regards,
Ray L.

It is possible. The C conversion functions sometimes have internal / static buffers. I have no idea if that is the case for the Libc stuff in your list.

In the immortal words of Emily Litella: Never mind!

I answered my own question by simply skipping the va_ calls, and vsnprintf, and simply printing the printf format string directly to the LCD, and the problem still occurs. That would seem to leave only the I2C communications as the source of the problem. Odd, as nothing else is using that I2C interface (this is on a Due, and there is a device on the other I2C interface).

Regards,
Ray L.

interrupt code use va_list/va_start/va_end and vsnprintf

Boy, are you sure you need to do that? And calling Serial.print from interrupt code works??? I read that the Arduino gods did some work to enable that, but... Eew.

After a quick look, all I can say is that it is safe IFF stdio FILE operations are safe. I can't find any sei/cli in the stdio source, so I doubt that it's safe.

Still, eew.

Cheers,
/dev

/dev:
Boy, are you sure you need to do that? And calling Serial.print from interrupt code works??? I read that the Arduino gods did some work to enable that, but... Eew.

After a quick look, all I can say is that it is safe IFF stdio FILE operations are safe. I can't find any sei/cli in the stdio source, so I doubt that it's safe.

Still, eew.

Cheers,
/dev

No, I do NOT call Serial from interrupt code, only from foreground code. I may be dumb but I'm not stupid.

I do use the va_ functions and vsnprintf in interrupt code, to format messages that are put into various queues, and are eventually written to various devices by the foreground thread. It all works flawlessly, except for the strings that get written to the LCD.

But, it now appears the problem is in either the Wire code, or the LCD driver.

Regards,
Ray L.

Found it! It's actually a hardware problem! There are several solenoids, and it appears one of them it creating a glitch that is whacking the I2C chip on the display. I added code that let me re-initialize the LCD when the problem occurs, and after the re-init, operation returns to normal.

So, I need to improve my snubbers, and all should be good again.

Regards,
Ray L.

Thank you for the follow-up.