From: Jack on
Hi,
I hear about poeple say standard library functions are not usable in a
multi-thread program.
Such as printf....asctime, what mostly people do in order to tackle this
problem?
I mean to use which other functions are acceptable by C++?
Thanks
Jack


From: Ulrich Eckhardt on
Jack wrote:
> I hear about poeple say standard library functions are not usable in a
> multi-thread program.

Nonsense. However, neither C nor C++ standards mention threads at all, so
their behaviour in a multithreaded program are formally not defined.

> Such as printf....asctime, what mostly people do in order to tackle this
> problem?

asctime() for example returns a pointer to a static buffer, which means its
content may be overwritten by a different thread. There are thread-safe
versions around using a thread-local buffer, alternatively there is
asctime_r() for example. In any case, those deficiencies are documented
including suggested alternatives. Just search the web.

Uli

--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932