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

  • SEARCH
  • Home
  • 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 4558506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:39:35+00:00 2026-05-21T17:39:35+00:00

I have a multi-threaded program where two separate threads are sending debug output to

  • 0

I have a multi-threaded program where two separate threads are sending debug output to std::clog and the outputs are interspersed. I would like to find an easy way to force the output to at least be kept separate except at line feeds in the output. This way, the debug output can be more readily interpreted. In some places, I’ve inserted a sleep(1) before the output and gather up the output into a string before sending it to clog to reduce the chances of collision, but I’d prefer a more robust and sure fired solution.

Is there an easy way to ensure that each thread writes a whole line at a time to std::clog before the other thread can get in and write its own line of output?

  • 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. Editorial Team
    Editorial Team
    2026-05-21T17:39:35+00:00Added an answer on May 21, 2026 at 5:39 pm

    There’s no particularly easy way of doing this, and there’s an extended discussion about it here: http://www.cplusplus.com/forum/general/27760/

    The problem is somewhat solved there with the creation of a new AtomicStream that writes an entire line atomically, before anything else is streamed (this is done with buffering tricks). You’ll need to come up with a similar solution. Sorry for the non-easy answer — thread synchronization will somehow have to make it into your solution.

    This may be derivative, but if your std::clog redirects to a file, you could also have multiple files for the multiple threads.

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

Sidebar

Related Questions

Let's say I have a container (std::vector) of pointers used by a multi-threaded application.
Say I have a multithreaded application made up of two separate threads and a
I have a simple multi-threaded program, with the following structure. public void someFunction() {
I have a multi-threaded Java program with a bunch of rules around threading: For
I have a multi-threaded Cocoa app that processes images. The program has a progress
I have a multi-threaded Delphi program creating multiple instance of some classes, and I
I have a multi-threaded C++ app which does 3D rendering with the OpenSceneGraph library.
I have a multi-threaded Windows application that occasionally deadlocks. Inevitably this happens on a
I have a multi-threaded Windows C++ app written in Visual Studio 6. Within the
I currently have heavily multi-threaded server application, and I'm shopping around for a good

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.