I will post what I found because it may be important for other plugin developers.<div><br></div><div>The Boehm-Weiser garbage collector assumes that it is initialized from the main thread of a program. That thread has to live as long as the garbage collector, and in some platforms it has some special properties, such as a fixed stack bottom.</div>
<div><br></div><div>In your case ECL is initialized from a secondary thread, because this is a GUI, and the garbage collector fails to recognize the limits of the stack. Furthermore, the thread in which it is initialized, is not known to the garbage collector, for it has not been registered with it.</div>
<div><br></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"><span style="color: #bf2e9d">static</span> pthread_t ecl_thread;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"><span style="color: #bf2e9d">static</span> pthread_mutex_t ecl_wait;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bf2e9d">static<span style="color: #000000"> </span>void<span style="color: #000000"> *</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">ecl_thread_entry(<span style="color: #bf2e9d">void</span> *aux)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #bf2e9d">int</span> argc = <span style="color: #2832cf">1</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"> <span style="color: #bf2e9d">char</span> * argv[<span style="color: #2832cf">256</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7340a3"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>cl_env_ptr<span style="color: #000000"> env;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span style="color: #000000"> argv[</span><span style="color: #2832cf">0</span><span style="color: #000000">] = </span><span style="color: #d62b24">""</span><span style="color: #000000">; </span>// cl_boot(argc, argv);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d62b24"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span><span style="color: #3f217c">printf</span><span style="color: #000000">(</span>"Hola2\n"<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3f217c"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>GC_register_my_thread<span style="color: #000000">(argv);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #7340a3">GC_stackbottom</span> = (<span style="color: #bf2e9d">void</span>*)(argv+<span style="color: #2832cf">255</span>);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7340a3"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span><span style="color: #3f217c">printf</span><span style="color: #000000">(</span><span style="color: #d62b24">"%x\n"</span><span style="color: #000000">, </span>GC_stackbottom<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #3f217c">cl_boot</span>(argc,argv);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3f217c"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span>env = </span>ecl_process_env<span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a482f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>CL_CATCH_ALL_BEGIN<span style="color: #000000">(env) {</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3f217c"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>pthread_mutex_lock<span style="color: #000000">(&</span><span style="color: #4b8186">ecl_wait</span><span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a482f"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span>} </span>CL_CATCH_ALL_END<span style="color: #000000">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3f217c"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>cl_shutdown<span style="color: #000000">();</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d62b24"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span><span style="color: #3f217c">printf</span><span style="color: #000000">(</span>"Exited\n"<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bf2e9d"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>return<span style="color: #000000"> </span>NULL<span style="color: #000000">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"><span style="color: #bf2e9d">void</span> InitPlugin()</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px"><span class="Apple-tab-span" style="white-space:pre"> </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>/*</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_TRAP_SIGSEGV, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_TRAP_SIGFPE, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_TRAP_SIGSEGV, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_TRAP_SIGINT, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_TRAP_SIGILL, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_TRAP_SIGBUS, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_TRAP_INTERRUPT_SIGNAL, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_SIGNAL_HANDLING_THREAD, 0); </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span>ecl_set_option(ECL_OPT_INCREMENTAL_GC, 0);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span class="Apple-tab-span" style="white-space:pre"> </span> */</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7a482f">#undef pthread_create</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3f217c"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>pthread_mutex_init<span style="color: #000000">(&</span><span style="color: #4b8186">ecl_wait</span><span style="color: #000000">, </span><span style="color: #bf2e9d">NULL</span><span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3f217c"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>pthread_mutex_lock<span style="color: #000000">(&</span><span style="color: #4b8186">ecl_wait</span><span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #3f217c">pthread_create</span>(&<span style="color: #4b8186">ecl_thread</span>, <span style="color: #bf2e9d">NULL</span>, ecl_thread_entry, <span style="color: #bf2e9d">NULL</span>);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo"><span style="color: #bf2e9d">void</span> DeinitPlugin()</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3f217c"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>pthread_mutex_unlock<span style="color: #000000">(&</span><span style="color: #4b8186">ecl_wait</span><span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008326"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>// cl_shutdown();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">}</p><div><br></div><p></p>I managed to solve the problems with the previous code. What it does is the following.</div><div><br></div><div>First of all it reserves some space (argv[256]) and registers the current thread with the given stack base (argv) and sets up the global application stack "bottom" (it is actually the top on Intel processors).</div>
<div><br></div><div>The value of GC_stackbottom only matters for the main thread and we will set it to be the location of the uppermost byte in the array argv. This should be safe as the thread is going to survive for a long time.</div>
<div><br></div><div>Finally, to shut down the plugin one needs some mechanism to communicate it to the thread that it should stop. I used locks, but this is a hack: you will need something better.<br clear="all"><br></div>
<div>Juanjo<br>-- <br>Instituto de Física Fundamental, CSIC<br>c/ Serrano, 113b, Madrid 28006 (Spain) <br><a href="http://juanjose.garciaripoll.googlepages.com">http://juanjose.garciaripoll.googlepages.com</a><br>
</div>