Stringbuf for concurrent writing And reading

F

fuenfzig

Hi all,

I want to use a single std::stringbuf for writing (by a std::eek:stream)
and for reading (by a std::istream), concurrently in two threads.
This came to my mind, because the code for reading should be the same
as with any ordinary istream, and it cannot be changed.

Now my problem is, that I do not get any data inside the reading loop
std:fstream tempfile("test.pdf", std::ios_base::eek:ut |
std::ios_base::trunc | std::ios_base::binary);
while (!is->eof()) {
is->read(buffer, bufferSize);
tempfile.write(buffer, is->gcount());
tempfile.flush;
}

The writing thread proceeds as expected and finally finishes writing.

Any hints or comments?

Thanks,
Christoph
 
F

fuenfzig

fuenfzig said:
Hi all,

I want to use a single std::stringbuf for writing (by a std::eek:stream)
and for reading (by a std::istream), concurrently in two threads.
This came to my mind, because the code for reading should be the same
as with any ordinary istream, and it cannot be changed.

Now my problem is, that I do not get any data inside the reading loop
SNIP

Hi again,

let me put it differently. I just tested, that it does not depend on
multi-threading.
If I write to the stringbuf in a std::eek:stream (or a std::iostream) and
then try to read
with a std::istream* is (or the same std::iostream* is), it does not
work either.
I immediatly get, (is->fail() == true) :-(
Also tried is->seekg(0); with the same result.

Does anybody have an example showing usage of stringbuf with
std::eek:stream and std::istream?
Or can somebody give some details on the internals, when
(is->fail()==true) and (is->eof()==true) does occur?

Thanks very much,
Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top