This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
C++ question - string_ostream - can you help?
- To: "Pthread-List" <pthreads-win32 at sourceware dot cygnus dot com>, "Open Discussion Mailing List" <leda-discussion at postino dot mpi-sb dot mpg dot de>
- Subject: C++ question - string_ostream - can you help?
- From: "Dennis Foreman" <dforeman at stny dot rr dot com>
- Date: Sat, 15 Jul 2000 09:41:36 -0400
- Reply-To: <foreman at binghamton dot edu>
I have a function (below), that I use to (hopefully) synchronize my output
from multiple threads to a single ofstream.
Unfortunately, I am getting strange results in the output: looks like data
is being either overlayed, or the stream is not being flushed. Can you offer
any suggestions?
pthread_mutex_t mystream_lock=PTHREAD_MUTEX_INITIALIZER;
ofstream dcout;
main()
{string_ostream dbgout;
dbgout<<"aha"<<endl;
myout(dbgout);
}
void myout(string_ostream& out)
{pthread_mutex_lock(&mystream_lock);
out.flush();
dcout<<out.str()<<flush; // debug stream file. NOT terminal I/O.
// str freezes the array!!!
out.rdbuf()->freeze(0);
out.seekp(0);
pthread_mutex_unlock(&mystream_lock);
}
regards,
D. J. Foreman
website: http://www.cs.binghamton.edu/~foreman/start.html