Is printf thread-safe?

S

Steven

Is printf thread-safe?

Someone tell me it isn't, however, I think it is.
If it isn't, then why?

Thank you in advance.
 
A

Artie Gold

Steven said:
Is printf thread-safe?

Yes. No. Maybe.
Since neither standard C nor standard C++ define a thread model, there's
no way to answer this question in the context of either newsgroup.
Someone tell me it isn't, however, I think it is.
If it isn't, then why?
It's an implementation issue. Please ask in a forum specific to your
platform -- or in
HTH,
--ag
 
S

Steven

Artie Gold said:
Yes. No. Maybe.
Since neither standard C nor standard C++ define a thread model,
there's no way to answer this question in the context of either
newsgroup.

It's an implementation issue. Please ask in a forum specific to your
platform -- or in
HTH,
--ag

I get it!
Thank you very much. :)
 
V

Vijay B

Hi

No the printf thread is not a safe one as we always use only one
output buffer for the printf's. As a result of this the printf
statements on a multi-threaded application are not safe. resort to
other techniques or place locks before printf(check to avoid
deadlocks). Use system calls such as read and write ..reading and
writing from standard output and standard input instead as these are
multi-processor and multi-thread safe.

Vijay
 
C

Chris Torek

No the printf thread is not a safe one as we always use only one
output buffer for the printf's.

I have already noted elsethread that this is system-dependent; I
will now add that, for BSD/OS, printf() *is* thread-safe.

How do you know the OP is using your particular system?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top