473,231 Members | 2,587 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,231 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 3082
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.