[project @ 2005-04-26 12:00:48 by simonmar]
authorsimonmar <unknown>
Tue, 26 Apr 2005 12:00:48 +0000 (12:00 +0000)
committersimonmar <unknown>
Tue, 26 Apr 2005 12:00:48 +0000 (12:00 +0000)
Add entry about non-blocking stdin and System.Cmd.{system,rawSystem}.

ghc/docs/users_guide/faq.xml

index 011a735..d2d05d7 100644 (file)
@@ -482,6 +482,31 @@ GHCi runtime linker: fatal error: I found a duplicate definition for symbol
          the <option>-x</option> option to <literal>ld</literal>.</para>
       </listitem>
     </varlistentry>
+
+    <varlistentry>
+      <term>GHC puts <literal>stdin</literal> and <literal>stdout</literal> in
+       non-blocking mode, which causes problems when I try to invoke a text
+       editor (for example) using <literal>System.Cmd.system</literal> or
+       <literal>System.Cmd.rawSystem</literal>.</term>
+
+      <listitem>
+       <para>The real problem is that Unix shares the non-blocking flag
+         between all processes accessing a file or stream.  It's impossible to
+         set this flag locally to a single process.  GHC's I/O library needs
+         non-blocking mode to properly support multithreaded I/O.</para>
+       
+       <para>Here's one possible fix, if you know that your program isn't
+         going to be accessing <literal>stdin</literal> from another thread
+         while the sub-process is running:</para>
+
+<programlisting>
+> main = do stdin `seq` return ()
+>           bracket (setFdOption stdInput NonBlockingRead False)
+>                   (\_ -> setFdOption stdInput NonBlockingRead True)
+>                   (\_ -> rawSystem "nvi" [])</programlisting>
+      </listitem>
+    </varlistentry>
+
   </variablelist>
 
 </chapter>