Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is fprintf threadsafe?

0 views
Skip to first unread message

Henry Zhang

unread,
Apr 29, 2002, 11:51:38 AM4/29/02
to
I tried to add a critical section to write attemps to my files. However, I
found it is as if unecessary...
the fprintf is already thread-safe?

correct me if I am wrong.


Neil Butterworth

unread,
Apr 29, 2002, 12:09:20 PM4/29/02
to
"Henry Zhang" <hzh...@saflink.com> wrote in message
news:e_dz8.21$2D1....@news2.telusplanet.net...

> I tried to add a critical section to write attemps to my files. However, I
> found it is as if unecessary...
> the fprintf is already thread-safe?

Standard C++, the topic of this newsgroup, has nothing to say about
threading and therefore nothing to say about the thread safety or otherwise
of standard functions. You need to ask this question in a newsgroup that
concerns itself with your specific C++ implementation.

NeilB


Jim Fischer

unread,
Apr 29, 2002, 3:23:17 PM4/29/02
to

"Henry Zhang" <hzh...@saflink.com> wrote in message
news:e_dz8.21$2D1....@news2.telusplanet.net...
> I tried to add a critical section to write attemps to my files. However, I
> found it is as if unecessary...
> the fprintf is already thread-safe?

No.

More specifically, the ISO/ANSI standards that define the C and C++
programming languages do not require, or even recommend, that the standard
C/C++ libraries be "thread safe" (whatever that may mean for a given
execution environment).

HOWEVER: Software vendors often add their own thread safety support to
various components in the standard C/C++ libraries. So if you want to find
out whether a given feature/component in a particular implementation of the
"standard" C/C++ library is thread safe (and if so, to what degree it is
thread safe), you'll need to read the documentation that the vendor
presumably supplied with the standard library you are using. Also, many
software vendors have their own public newsgroups / mailing lists where the
users of that vendor's software products (e.g., a particualr vendor's C/C++
library) can ask questions about the vendor's software products. [n.b.
Platform- and vendor-specific HOWTOs are beyond the scope of the C/C++
language groups on Usenet (ref: see the FAQ docs for those groups).]


Jim


Alexander Terekhov

unread,
Apr 30, 2002, 4:30:02 AM4/30/02
to
< Followup-To: comp.programming.threads >

Henry Zhang wrote:
>
> I tried to add a critical section to write attemps to my files. However, I
> found it is as if unecessary...
> the fprintf is already thread-safe?

Be careful w.r.t. the implied meaning of "thread-safe" term.
On any POSIX (or SUS; even better) compliant impl. (standard
extension to ANSI C), it IS thread-safe... however, I guess,
you should really read this (especially the 1st link ;-)):

http://www.opengroup.org/onlinepubs/007904975/functions/flockfile.html

http://www.opengroup.org/onlinepubs/007904975/functions/fprintf.html
("Characters generated by fprintf() and printf() are printed as if
fputc() had been called.")

http://www.opengroup.org/onlinepubs/007904975/functions/fputc.html

http://www.opengroup.org/onlinepubs/007904975/functions/putc.html

http://www.opengroup.org/onlinepubs/007904975/functions/putc_unlocked.html

> correct me if I am wrong.

Uhmm. To me: NOT clear yet! ;-)

regards,
alexander.

0 new messages