<div dir="ltr"><div><div>Thanks! Turning off R&#39;s stack limit checks will not work. I tried this<br>and this leads to a segfault. Fortunately, your experiments led me<br>to a work-around: simply use the -fno-ghci-sandbox flag.<br>
<br></div>R is not thread-safe, and this flag tells ghci to run computations<br></div><div>in the main thread instead of forking.<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Sep 28, 2013 at 1:29 AM, GHC <span dir="ltr">&lt;<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">#8371: ghci byte compiler + FFI crashes when used with embedded R<br>
</div>-------------------------------+----------------------------------<br>
<div class="im">        Reporter:  dsamperi    |            Owner:<br>
            Type:  bug         |           Status:  new<br>
        Priority:  normal      |        Milestone:<br>
       Component:  GHCi        |          Version:  7.6.3<br>
</div>      Resolution:              |         Keywords:<br>
<div class="im">Operating System:  Linux       |     Architecture:  x86_64 (amd64)<br>
 Type of failure:  GHCi crash  |       Difficulty:  Unknown<br>
       Test Case:              |       Blocked By:<br>
        Blocking:              |  Related Tickets:<br>
</div>-------------------------------+----------------------------------<br>
<br>
Comment (by rwbarton):<br>
<br>
 I can reproduce this without ghci, by putting a forkIO around the body of<br>
 main (and adding a threadDelay in the main thread).<br>
<br>
 It seems to just be an interaction between R&#39;s method for determining the<br>
 base address of the stack and the way pthread allocates stacks for new<br>
 threads. Try this C example program `pt.c`.<br>
<br>
 {{{<br>
 #include &lt;stdio.h&gt;<br>
 #include &lt;unistd.h&gt;<br>
 #include &lt;pthread.h&gt;<br>
<br>
 int Rf_initEmbeddedR(int argc, char **argv);<br>
<br>
 void *foo(void *blah)<br>
 {<br>
     char *args[] = {&quot;pt&quot;, &quot;--gui=none&quot;, &quot;--silent&quot;, &quot;--vanilla&quot;};<br>
     int r;<br>
     setenv(&quot;R_HOME&quot;, &quot;/usr/lib/R&quot;, 1);<br>
     r = Rf_initEmbeddedR(sizeof(args)/sizeof(args[0]), args);<br>
     printf(&quot;r = %d\n&quot;, r);<br>
 }<br>
<br>
 int main(void)<br>
 {<br>
     pthread_t tid;<br>
     pthread_create(&amp;tid, NULL, foo, NULL);<br>
     while (1)<br>
         sleep(1);<br>
     return 0;<br>
 }<br>
 }}}<br>
<br>
 {{{<br>
 rwbarton@adjunction:/tmp$ gcc -o pt pt.c  -lpthread -lR<br>
 rwbarton@adjunction:/tmp$ ./pt<br>
<div class="im"> Error: C stack usage is too close to the limit<br>
 Error: C stack usage is too close to the limit<br>
</div> r = 1<br>
 }}}<br>
<br>
 It would probably be best to just disable R&#39;s stack limit checks, if<br>
 possible.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Ticket URL: &lt;<a href="http://ghc.haskell.org/trac/ghc/ticket/8371#comment:6" target="_blank">http://ghc.haskell.org/trac/ghc/ticket/8371#comment:6</a>&gt;<br>
</font></span><div class="HOEnZb"><div class="h5">GHC &lt;<a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.org/ghc/</a>&gt;<br>
The Glasgow Haskell Compiler<br>
</div></div></blockquote></div><br></div>