This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++ question - string_ostream - can you help?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]