public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* RE: Simple question.
@ 2002-08-21 12:11 Schwartz, Barry
  0 siblings, 0 replies; 4+ messages in thread
From: Schwartz, Barry @ 2002-08-21 12:11 UTC (permalink / raw)
  To: 'Kyle Boon', pthreads-win32

If it were me...
I would create another thread that manged an output queue.  I would arrange for the contributing threads to write their output to this thread's input method -- as one "atomic" text block.  Then I would call some other method to "print" it or queue it up for printing.  The management of sending chars to the screen would be done by this queue manager and it would be the only place I would put an output call in all of my code.  Also, I would consider alternatives to cout if you have any.


-----Original Message-----
From: Kyle Boon [mailto:kboon@bmi.osu.edu]
Sent: Wednesday, August 21, 2002 12:03 PM
To: pthreads-win32@sources.redhat.com
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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Simple question.
  2002-08-21 12:02 Kyle Boon
  2002-08-21 14:59 ` Wayne Robin Isaacs
@ 2002-08-21 15:22 ` Wayne Robin Isaacs
  1 sibling, 0 replies; 4+ messages in thread
From: Wayne Robin Isaacs @ 2002-08-21 15:22 UTC (permalink / raw)
  To: Kyle Boon, pthreads-win32

Here's an example:

#include <iostream.h>
#include <process.h>
#include <strstrea.h>

// use a buffer to collect your data before the "cout" call

void threadfn(void*) { 
 strstream x;
 for(int i=100;i--;) {
  x << "o" << "o" << '\n' << '\0';
  cout << x.str();
  }
 }

Wayne


----- 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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Simple question.
  2002-08-21 12:02 Kyle Boon
@ 2002-08-21 14:59 ` Wayne Robin Isaacs
  2002-08-21 15:22 ` Wayne Robin Isaacs
  1 sibling, 0 replies; 4+ messages in thread
From: Wayne Robin Isaacs @ 2002-08-21 14:59 UTC (permalink / raw)
  To: Kyle Boon, pthreads-win32

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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Simple question.
@ 2002-08-21 12:02 Kyle Boon
  2002-08-21 14:59 ` Wayne Robin Isaacs
  2002-08-21 15:22 ` Wayne Robin Isaacs
  0 siblings, 2 replies; 4+ messages in thread
From: Kyle Boon @ 2002-08-21 12:02 UTC (permalink / raw)
  To: pthreads-win32

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-08-21 22:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-21 12:11 Simple question Schwartz, Barry
  -- strict thread matches above, loose matches on Subject: below --
2002-08-21 12:02 Kyle Boon
2002-08-21 14:59 ` Wayne Robin Isaacs
2002-08-21 15:22 ` Wayne Robin Isaacs

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).