This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[971008] iostream deadlock problem
- To: egcs-bugs at cygnus dot com
- Subject: [971008] iostream deadlock problem
- From: Bob Glickstein <bobg at zanshin dot com>
- Date: Fri, 17 Oct 1997 15:18:52 -0700
- Organization: Zanshin Inc., Marin County, CA
- Reply-To: Bob Glickstein <bobg at zanshin dot com>
Howdy. My environment is linux 2.0.30, glibc 2.0.5c, egcs 1997-10-08.
I have an iostream (derived from "sockets++" classes) for reading from
and writing to an IMAP server. The app that uses this iostream is
multithreaded. One thread loops on input from the server; another
thread periodically sends output to the server.
The problem is that the reading thread, which spends most of its time
in a blocking read, obtains a lock on the iostream's underlying
streambuf, excluding the writing thread, which tries to acquire the
same lock. The app wedges as soon as it tries to write anything to
the server.
I've worked around this problem by not using an iostream. When I use
a separate ifstream and ofstream (initialized from the same socket
fd), it works great. And the iostream approach worked great until I
began using egcs.
My question is, is it proper for the iostream implementation to allow
this deadlock to occur? Shouldn't one thread be able to read from an
iostream while another one is writing? Suppose the iostream is used
for communication between two threads. That should be possible,
right? But in the current implementation, it's not.
Is this a bug, or do I have to live with it?
Thanks in advance.
--
Bob Glickstein <bobg@zanshin.com>
Chief Architect, Zanshin Inc.