Stringbuf for concurrent writing And reading

Discussion in 'C++' started by fuenfzig, Nov 22, 2006.

  1. fuenfzig

    fuenfzig Guest

    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
    fuenfzig, Nov 22, 2006
    #1
    1. Advertising

  2. fuenfzig

    fuenfzig Guest

    fuenfzig schrieb:

    > 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
    fuenfzig, Nov 23, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pep
    Replies:
    6
    Views:
    811
  2. Replies:
    7
    Views:
    514
  3. Replies:
    0
    Views:
    534
  4. Andre Paim

    Problem with stringbuf

    Andre Paim, Aug 15, 2008, in forum: C++
    Replies:
    1
    Views:
    357
    Fraser Ross
    Aug 16, 2008
  5. Steve Howell
    Replies:
    2
    Views:
    924
    Dennis Lee Bieber
    Mar 27, 2012
Loading...

Share This Page