Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Stringbuf for concurrent writing And reading

Reply
Thread Tools

Stringbuf for concurrent writing And reading

 
 
fuenfzig
Guest
Posts: n/a
 
      11-22-2006
Hi all,

I want to use a single std::stringbuf for writing (by a std: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: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

 
Reply With Quote
 
 
 
 
fuenfzig
Guest
Posts: n/a
 
      11-23-2006

fuenfzig schrieb:

> Hi all,
>
> I want to use a single std::stringbuf for writing (by a std: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: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: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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: concurrent file reading/writing using python Steve Howell Python 2 03-27-2012 01:17 PM
Problem with stringbuf Andre Paim C++ 1 08-16-2008 12:23 PM
Remove from std::stringbuf marco.minerva@gmail.com C++ 0 04-15-2008 04:49 PM
Reading and Writing <byte> and <char> Values from and to Disk Quickly kvnsmnsn@hotmail.com Java 7 07-06-2006 04:21 AM
problems locating the concurrent EDU.oswego.cs.dl.util.concurrent package Pep Java 6 08-16-2005 07:26 AM



Advertisments