473,395 Members | 1,656 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,395 software developers and data experts.

stream in multiprocess (multithread) apps

Hello.
I have some function f(stream* out) that makes text-output into stream
(*out) i.e. (*out)<<"Hello"<<endl;. The (*out) can be cout, ofstream, a
strstream, etc. This function working in the background process (thread).
The main process need to receive this outout for the further transfering
into console-like window or something else.
How can I do this? Need I use a pipe? How should I connect the pipe not to
files, but to streams?
Please, give me a piece of sample code!
Thanx.
Shesero Michael

Jul 22 '05 #1
4 3089
Hi,

"Michael Shestero" <sh******@cyber.miem.edu.ru> wrote in message
news:br************@ID-54498.news.uni-berlin.de...
Hello.
I have some function f(stream* out) that makes text-output into stream
(*out) i.e. (*out)<<"Hello"<<endl;. The (*out) can be cout, ofstream, a
strstream, etc. This function working in the background process (thread).
The main process need to receive this outout for the further transfering
into console-like window or something else.
How can I do this? Need I use a pipe? How should I connect the pipe not to
files, but to streams?
Please, give me a piece of sample code!
Thanx.
Shesero Michael

In most OS'es threads share data. So writing it into a string and reading it
from anothere thread should work. Protect the string with a mutex.

Regards, Ron AF Greve
Jul 22 '05 #2
> "Michael Shestero" <sh******@cyber.miem.edu.ru> wrote in message
news:br************@ID-54498.news.uni-berlin.de...
Hello.
I have some function f(stream* out) that makes text-output into stream
(*out) i.e. (*out)<<"Hello"<<endl;. The (*out) can be cout, ofstream, a
strstream, etc. This function working in the background process (thread). The main process need to receive this outout for the further transfering
into console-like window or something else.
How can I do this? Need I use a pipe? How should I connect the pipe not to files, but to streams?
Please, give me a piece of sample code!
Shesero Michael
In most OS'es threads share data. So writing it into a string and reading

it from anothere thread should work. Protect the string with a mutex.


Yes, these threads share memory.
The question is not general one "how to do it", but releated streams and
derived classes.
The important point is that I don't want to change f(stream* out) function
(the code isn't mine),
so I cannot use mutexes etc in it. In other words, the question was: Is it
possible to make multithreads-safe exchane through streams/iostreams or
derived (without mutexes, signals, etc) or not; and if it is possible then
how can I do it?

If it is not in general possible with streams may be it is somehow possible
with pure FILE* output?

Note: I have some reason to guess it is possible becouse of following: I
actually can redirect cout, cin and cerr for child process (that doesn't
share memory with parent) using pipes. There are several examples in
internet for Windows and Unix. For example, HTTP-server do this redirection
on calling for external cgi-program which receive parameters and push result
through stdin/stdout.
I will also be quite satisfied if I you told me how to do such thing not
with separated child process, but with thread (in shared memory).

Thanx.
Shestero Michael

Jul 22 '05 #3
Michael Shestero wrote:
"Michael Shestero" <sh******@cyber.miem.edu.ru> wrote in message
news:br************@ID-54498.news.uni-berlin.de...
Hello.
I have some function f(stream* out) that makes text-output into stream
(*out) i.e. (*out)<<"Hello"<<endl;. The (*out) can be cout, ofstream, a
strstream, etc. This function working in the background process
(thread).
The main process need to receive this outout for the further transfering
into console-like window or something else.
How can I do this? Need I use a pipe? How should I connect the pipe not
to
files, but to streams?
Please, give me a piece of sample code!
Shesero Michael

In most OS'es threads share data. So writing it into a string and reading


it
from anothere thread should work. Protect the string with a mutex.

Yes, these threads share memory.
The question is not general one "how to do it", but releated streams and
derived classes.
The important point is that I don't want to change f(stream* out) function
(the code isn't mine),
so I cannot use mutexes etc in it.In other words, the question was: Is it
possible to make multithreads-safe exchane through streams/iostreams or
derived (without mutexes, signals, etc) or not; and if it is possible then
how can I do it?


The fact that you can't change the f() function doesn't mean you can't
use mutexes.

Have you got a threadsafe stringstream? If not, write one. (Hint:
wrap or derive from the non-threadsafe version.)

If it is not in general possible with streams may be it is somehow possible
with pure FILE* output?

Note: I have some reason to guess it is possible becouse of following: I
actually can redirect cout, cin and cerr for child process (that doesn't
share memory with parent) using pipes. There are several examples in
internet for Windows and Unix. For example, HTTP-server do this redirection
on calling for external cgi-program which receive parameters and push result
through stdin/stdout.
I will also be quite satisfied if I you told me how to do such thing not
with separated child process, but with thread (in shared memory).

Thanx.
Shestero Michael


Jul 22 '05 #4
[...]
The fact that you can't change the f() function doesn't mean you can't
use mutexes.

Have you got a threadsafe stringstream? If not, write one. (Hint:
wrap or derive from the non-threadsafe version.)

Thanx a lot. That is exactly I am asking for.
Could anybody send me a URL with a such sample code or a guide how to write
"threadsafe stringstream".

Shestero Michael

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alice | last post by:
Hello I have four multithread windows applications(vb.net) interacting and running on the same machine(windows 2000 with .net framework 1.0). All of them start a new thread each time Filewatcher's...
0
by: r_obert | last post by:
Hello, I'm trying to create a worker thread for my VC++ program, and was wondering whether I should be linking with the Multithread /MT or Multithread DLL /MD option? I'm not quite sure, in...
9
by: Bryan Olson | last post by:
Here's a module to show stderr output from console-less Python apps, and stay out of the way otherwise. I plan to make a ASPN recipe of it, but I thought I'd run it by this group first. To use...
3
by: Alina | last post by:
Did anybody knows a way to secure the read/write multithreading and multiprocess in an xml file ? Thank you
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
2
by: zhebincong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting...
0
by: fred | last post by:
I need some help in trying to understand how to make myCollection (inherited from CollectionBase) multithread safe. Taking my implementation of the Add Sub and a readonly property Item. Public...
6
by: jmartin | last post by:
Hi, I have made a multithread version of a program (load a file into database), and with two processors I get the double of time in the multithread than in the process (unithread) version. I...
4
by: Armin Zingler | last post by:
Hi, how can I debug multithreaded apps in the express version? There is no threads window. I press Break, but I always see the same thread. But I want to debug the other thread that I started....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.