public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: "Wayne Robin Isaacs" <wisaacs@io.com>
To: "Kyle Boon" <kboon@bmi.osu.edu>, <pthreads-win32@sources.redhat.com>
Subject: Re: Simple question.
Date: Wed, 21 Aug 2002 14:59:00 -0000	[thread overview]
Message-ID: <000f01c2495e$0b2bab80$1d2c4142@victory> (raw)
In-Reply-To: <20020821190248.28CFB3BDBF@toledo.bmi.ohio-state.edu>

Hi, Kyle.
As long as you use multi-threaded libraries in your project->settings, "cout" will be thread-safe in VC++.   I'm not sure how
you're calling "cout", but there may be a discrepancy in usage between iostream/Linux and iostream/Windows.   If you use
statements like:


void threadfn(void*) { for(int i=100;i--;) cout << "o" << "o" << endl; }

main() {
    _beginthread(threadfn,0,0);
    for(int i=100;i--;) cout << "x" << "x" << endl;
    getchar();
}


.. then your output should be all mixed up, because each line compiles to three separate calls to "cout".   The gcc compiler
may combine these calls as an optimization, but you shouldn't code assuming that, because it's an implementation artifact.

Rather than implementing a serialization thread, it might be simpler to send your strings to a stringbuffer first, then
output that buffer in a single "cout" call.

Wayne Isaacs


----- Original Message -----
From: "Kyle Boon" <kboon@bmi.osu.edu>
To: <pthreads-win32@sources.redhat.com>
Sent: Wednesday, August 21, 2002 3:02 PM
Subject: Simple question.


> I'm not sure if this is the right place for my question - so I apolgize in
> advance if it not.
>
> First some quick background. I am a college undergrad charged with porting a
> linux app to the win32 platform. I chose this pthreads implementation to make
> the task much easier. So far it's worked very well. My only question is how
> people deal with console output. I have multiple threads using cout to print
> things to the console, but the output is all jumbled up. If I try to link
> with a thread safe version of the standard library on windows, I get all
> sorts of linker errors. It seems like people must have had to work around
> this before, but I haven't been able to find any information about it.
>
> Any help would be greatly appreciated.
> Kyle Boon
>

  reply	other threads:[~2002-08-21 21:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-21 12:02 Kyle Boon
2002-08-21 14:59 ` Wayne Robin Isaacs [this message]
2002-08-21 15:22 ` Wayne Robin Isaacs
2002-08-21 12:11 Schwartz, Barry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000f01c2495e$0b2bab80$1d2c4142@victory' \
    --to=wisaacs@io.com \
    --cc=kboon@bmi.osu.edu \
    --cc=pthreads-win32@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).