473,414 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Is printf thread-safe?

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.
--
Steven Ding
Jul 19 '05 #1
5 20198
Steven wrote:
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 news:comp.programming.threads.

HTH,
--ag

--
Artie Gold -- Austin, Texas

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 19 '05 #2
Artie Gold <ag***@bga.com> wrote in news:3E**************@bga.com:
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 news:comp.programming.threads.

HTH,
--ag


I get it!
Thank you very much. :)

--
Steven Ding
Jul 19 '05 #3

Steven wrote:

Is printf thread-safe?


http://groups.google.com/groups?selm...4E99D%40web.de

regards,
alexander.
Jul 19 '05 #4
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

Steven <wj****@szapsoft.com> wrote in message news:<Xn*******************@202.108.36.140>...
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.

Jul 19 '05 #5
>Steven <wj****@szapsoft.com> wrote in message news:<Xn*******************@202.108.36.140>...
Is printf thread-safe?

In article <65**************************@posting.google.com >
Vijay B <vi*****@hotmail.com> writes: 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?
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: iam1708 via DotNetMonster.com | last post by:
I was looking at the docs for Thread and can't understand the different between "unnamed data slot "and "data slot".and docs in Thread.GetData() say "Threads use a local store memory mechanism to...
11
by: danieldsmith | last post by:
hello all, i have run into a problem where i cannot start more than 1021 threads in a python program, no matter what my ulimit or kernel settings are. my program crashes with 'thread.error:...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
3
by: CAIBird | last post by:
hi, i'v been coding with c++/cli and i hit a terrible problem. i created a class library project and add a ref class(abstract) with some static member functions like: //////////////...
14
by: juanpolotto | last post by:
Hi. I'm write a "passthru" application which is reading from one socket and writing to a pool of outcoming sockets. From time to time I have date duplicated in the socket and when I debug the...
0
by: Yue Fei | last post by:
I have a multi thread python code, threads can start immediately if I run on command line, but I can get them started right the way if I call the same code from C/C++. test code like this: from...
3
by: CMorgan | last post by:
Hi everybody, I am experiencing an annoying problem with fork() and execv(). In my program I need to launch the "pppd" from a thread, so, I create a new process with fork and then in the child...
2
by: Chameleon | last post by:
Why this strange output? Why so many d'tor calls? The code: ---------------------------------------------------------- #include <cstdio> #include <boost/thread/thread.hpp> class A {
1
by: Chris M. Thomasson | last post by:
FWIW, here is a quick example (in the form of a fully compliable program with error checking omitted) of how I use POSIX threads within a C++ environment:...
3
by: ekailan | last post by:
I am working on creating windows.h to creat tow threads, each thread takes tow files as input, the function that each thread excute is tested and work 100%,the problem is that one thread could work...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.