> "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