Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 110885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:17:51+00:00 2026-05-11T02:17:51+00:00

Is writing to stdout using printf thread-safe on Linux? What about using the lower-level

  • 0

Is writing to stdout using printf thread-safe on Linux? What about using the lower-level write command?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:17:52+00:00Added an answer on May 11, 2026 at 2:17 am

    It’s not specified by the C standard — it depends on your implementation of the C standard library. In fact, the C standard doesn’t even mention threads at all, since certain systems (e.g. embedded systems) don’t have multithreading.

    In the GNU implementation (glibc), most of the higher-level functions in stdio that deal with FILE* objects are thread-safe. The ones that aren’t usually have unlocked in their names (e.g. getc_unlocked(3)). However, the thread safety is at a per-function call level: if you make multiple calls to printf(3), for example, each of those calls is guaranteed to output atomically, but other threads might print things out between your calls to printf(). If you want to ensure that a sequence of I/O calls gets output atomically, you can surround them with a pair of flockfile(3)/funlockfile(3) calls to lock the FILE handle. Note that these functions are reentrant, so you can safely call printf() in between them, and that won’t result in deadlock even thought printf() itself makes a call to flockfile().

    The low-level I/O calls such as write(2) should be thread-safe, but I’m not 100% sure of that – write() makes a system call into the kernel to perform I/O. How exactly this happens depends on what kernel you’re using. It might be the sysenter instruction, or the int (interrupt) instruction on older systems. Once inside the kernel, it’s up to the kernel to make sure that the I/O is thread-safe. In a test I just did with the Darwin Kernel Version 8.11.1, write(2) appears to be thread-safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I got some help and suggestions, then this is how… May 11, 2026 at 11:40 am
  • added an answer If you are using events, it should marshal over to… May 11, 2026 at 11:40 am
  • added an answer Your best bet is to use Jacob (or some other… May 11, 2026 at 11:40 am

Related Questions

Is writing to stdout using printf thread-safe on Linux? What about using the lower-level
I have a system which is writing files to a folder using FTP. I
Is there a tool that will show me what applications are writing to the
I am trying to snoop on a log file that an application is writing
Is there any advantage to writing a PHP conditional like this: if ($variable !=
What is the ideal code to logging ratio? I'm not used to writing logs
How can I rewrite or is there a way to writing my own custom
I am writing some code to determine whether a network domain is registered. For
My company is looking into writing a custom application that will need to perform
Programming is learned by writing programs. But code reading is said to be another

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.