C++ question - string_ostream - can you help?
Dennis Foreman
dforeman@stny.rr.com
Sat Jul 15 06:41:00 GMT 2000
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
More information about the Pthreads-win32
mailing list