473,669 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stringbuf for concurrent writing And reading

5 New Member
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 2299
smartway
24 New Member
How did you define 'is'?
Nov 22 '06 #2
fuenfzig
5 New Member
How did you define 'is'?
is is an istream* managed by a boost::shared_p tr
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
fuenfzig
5 New Member
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
3792
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 of the problem, or how to avoid conflicts, which I know how to solve; I just need a few atomic primitive shared among any PHP processes that may be running. I could even have a separate process serializing all operations if such a thing is...
2
1796
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 to imply so. http://www.codeguru.com/net_asp/CacheSync.html However, this article states that the Cache object has a built in lock mechanism. http://www.fawcette.com/vsm/2003%5F05/magazine/columns/aspnet/
6
6443
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 fairly common idiom (at least in the Java/UNIX/Win32 worlds) where a socket connection is established and the program then utilises two threads: one dedicated to reading from the socket and the other one concurrently writing to the socket - both using...
1
2690
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 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::out | std::ios_base::trunc |...
0
1163
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 char * is very large, I don't want the stringbuf variable to make a copy of the array, rather I would like the stringbuf variable to reference the char array via the char *. Hope this makes sense. PK
1
1883
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 concurrency issues. However, what do I need to do to allow multiple threads to traverse the container without synchronization/mutual-exclusion - but ensure that synchronization/mutual-exclusion is there when the container is trying to be both changed...
0
1479
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: #! /usr/bin/python import threading, random import time def myPrint(str):
6
1434
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
1291
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. -- Marco Minerva , marco.minerva@gmail.com http://blogs.ugidotnet.org/marcom
0
1447
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 element is a single character, and all elements are separated by whitespace characters". It just so happens that 0x0c is the ascii formfeed character, which is a whitespace character, to it is interpreted as a delimitor between the 0x01
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8894
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8587
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.