473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Stringbuf for concurrent writing And reading

Hi all,

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

Now my problem is, that a do not get any data in the reading loop
std::ofstream tempfile("test.pdf",
std::ios_base::out | 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? What are my misconceptions?

Thanks,
Christoph
Nov 22 '06 #1
3 2286
How did you define 'is'?
Nov 22 '06 #2
How did you define 'is'?
is is an istream* managed by a boost::shared_ptr
Expand|Select|Wrap|Line Numbers
  1. typedef boost::shared_ptr<std::istream> IStreamP;
  2. IStreamP is = data->getIStream();
The istream is created with the same std::stringbuf used during writing (in a ostream of course!).
It seems that I do not get any content during reading or the read pointer is always at the end or ..
Nov 22 '06 #3
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:: ostream (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:: ostream 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
Nov 23 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bruno Barberi Gnecco | last post by:
I'm developing a collaborative application in PHP which accesses local files and may modify them. How can I synchronize the multiple accesses? Note that I'm not worried about the algorithmic part...
2
by: Manit Chanthavong | last post by:
I just read, that concurrent read & writes to the Cache object corrupts the data. My question is, Is it necessary to create a mechanism for locking when writing to the cache? This article seems...
6
by: roblugt | last post by:
I have what I imagine is a well-known .Net networking problem, but even though I've Googled for some time I've not yet come across a thread where this has been fully explained... There is a...
1
by: fuenfzig | last post by:
Hi all, I want to use a single std::stringbuf for writing (by a std::ostream) and for reading (by a std::istream), concurrently in two threads. This came to my mind, because the code for reading...
0
by: pjks | last post by:
Does anyone know how to assign a char * into a variable of type stringbuf without the stringbuf making a copy of what is pointed to by the char * Reason: If the char array pointed to by the...
1
by: illegal.prime | last post by:
So I have a container of objects that I don't want to iterate across when I'm modifying it. I.E. I lock on adds and deletes to the container - so that my traversals of it don't result in...
0
by: Gerardo Herzig | last post by:
Hi all. Im having some "problems" with a small concurrent plpython function. Based on a small example about concurrent programming, there is some code which works fine under python: #!...
6
by: tenxian | last post by:
It is said as for code, developing a website that can stand 10,000 concurrent visitors is much different from developing a website that can stand 1,000 concurrent visitors, is it true?
0
by: marco.minerva | last post by:
Hi all! I'm using the std::stringbuf object. I insert a string in it using the "sputn" method, but how I can I remove, for example, the first 3 characters from the buffer? Thanks in advance....
0
by: Sam | last post by:
Andre Paim writes: Becase std::istream_iterator<chardoes not mean "return one character at a time from a std::istream". It means "return the next element from a std::istream, where each...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.