bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Thread safe I/O streams implementation questions


From: Daniel E Baumann
Subject: Thread safe I/O streams implementation questions
Date: Tue, 14 May 2002 22:05:38 -0500
User-agent: Mutt/1.3.28i

Hello all, I am now hacking on some thread-safe iostreams for GNU
Common C++ and in the processing learning a LOT about c++ i/o
streams. I have been struggling lately with a few issues and I was
wondering if you guys could provide some of your guidance and
input. The main thing is when to lock the streams and/or buffer. I am
wondrring what does one make atomic, do you do it at each operator<<
or operator>> call or should you wait until the thread flushes the
buffer with and 'endl' or 'flush' manipulator call in the stream? I
also found this URL to be very helpful, but of course there's that
condition they mention where if 2 threads are doing:

http://www.roguewave.com/support/docs/SourcePro/stdlibug/44-2.cfm

Thread1:
pout << "hello world" << endl; 

Thread2:
cout << "hello world" << endl;

Thread 1 could be preempted and hence the output is not atmoic with
respect to the string and the newline. So should thread safe streams
be atomic wrt all output plus until they flush the buffer or should
they be allowed to interleave? I.e., is the Rogue Wave method good
enough? Also I would like to add identifier information for each
stream like "[pid][tid] hello world" so you know where/which thread
the i/o is coming from.

Please let me know what you think.

Dan
-- 
Daniel E Baumann      address@hidden

And if cynics ridicule freedom, ridicule community...if ``hard nosed 
realists'' say that profit is the only ideal...just ignore them, and use 
copyleft all the same.
      -- RMS



reply via email to

[Prev in Thread] Current Thread [Next in Thread]