473,775 Members | 3,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20273
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.progr amming.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.co m> 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.progr amming.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****@szapsof t.com> wrote in message news:<Xn******* ************@20 2.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****@szapsof t.com> wrote in message news:<Xn******* ************@20 2.108.36.140>.. .
Is printf thread-safe?

In article <65************ **************@ posting.google. com>
Vijay B <vi*****@hotmai l.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
453
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 store thread-specific data." what is "thread-specific data"? Best regards wmt email:iam1708@hotmail.com
11
4346
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: can't start new thread' when it tries to start the 1021st thread. in addition to tweaking my ulimit settings, i have also verified that the version of glibc i'm using has PTHREAD_THREADS_MAX defined to be 16374. i have posted my test program below...
188
17434
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
3
1733
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: ////////////// CrawlerWrapper.h public ref class CrawlerWrapper abstract sealed {
14
1745
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 function below, using step by step, I find that printf("LINE 1\n"); executes more than once every time I hit F10 (Visual C++). I never saw something like that. Very weird!!!!!!!!!!! unsigned __stdcall inWriteIncomingSocket(void* data) {
0
1528
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 threading import Thread import thread class testThread(Thread): def __init__ (self, id): Thread.__init__(self) self.id = id def run(self):
3
5687
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 process I launch with execv the pppd to connect an embedded system to internet. The problem is that pppd fails. I have made two test program just to discard bugs (my applications is really big) and the result is that when I call execv from a...
2
2335
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
3594
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: _________________________________________________________________ /* Simple Thread Object ______________________________________________________________*/ #include <pthread.h> extern "C" void* thread_entry(void*);
3
1782
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 at atime ? I mean one function is excuted this is the threading code i dont know what is the problem. I tried to pass different files to each thread but its still not working *************************** ...
0
9623
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9458
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10276
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10055
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9918
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7465
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4023
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2855
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.