[Ecls-list] cl_boot() segfaults when called not in the main thread

Kamil Shakirov kamils80 at gmail.com
Thu Jul 16 08:46:39 UTC 2009


On Thu, 2009-07-16 at 09:41 +0200, Juan Jose Garcia-Ripoll wrote:
> >
> > I have tested it on GNU/Linux x86_64 (Ubuntu 9.04) and it is working
> > fine, but it still segfaults on Linux 32bit with the message "Collecting
> > from unknown thread.". The main thread calls cl_boot() when application
> > is started, ecl_import_current_thread() gets called in the second thread
> > before other calls to ECL:
> 
> Hi Kamil, I think the problem might be due to the fact that the thread
> is not registered with the garbage collector. This has nothing to do
> with the architecture, but with how the garbage collector library is
> used.
> 
> If you read your previous emails, you will see that the garbage
> collector library intercepts your calls to the POSIX thread creation
> routines. This is what should normally happen. I guess on your 32bits
> box this is not occurring.
> 
> Could you try calling the functions below, found in <ecl/gc/gc.h> or
> <gc/gc.h> or <gc.h>, on entrance and on exit of your thread? If it
> works I will add them to what ECL is doing for registering threads.
> 

Good news. Running GC_register_my_thread() before
ecl_import_current_thread(), and GC_unregister_my_thread() after
ecl_release_current_thread() does the trick. it is working on linux-x86
now. Thank a lot, Juan.

> Juanjo
> 
> /* Register the current thread, with the indicated stack base, as	*/
> /* a new thread whose stack(s) should be traced by the GC.  If a 	*/
> /* platform does not implicitly do so, this must be called before a	*/
> /* thread can allocate garbage collected memory, or assign pointers	*/
> /* to the garbage collected heap.  Once registered, a thread will be	*/
> /* stopped during garbage collections.					*/
> /* Return codes:	*/
> #define GC_SUCCESS 0
> #define GC_DUPLICATE 1	/* Was already registered.	*/
> #define GC_NO_THREADS 2	/* No thread support in GC.  	*/
> #define GC_UNIMPLEMENTED 3	/* Not yet implemented on this platform. */
> GC_API int GC_register_my_thread(struct GC_stack_base *);
> 
> /* Unregister the current thread.  The thread may no longer allocate	*/
> /* garbage collected memory or manipulate pointers to the		*/
> /* garbage collected heap after making this call.			*/
> /* Specifically, if it wants to return or otherwise communicate a 	*/
> /* pointer to the garbage-collected heap to another thread, it must	*/
> /* do this before calling GC_unregister_my_thread, most probably	*/
> /* by saving it in a global data structure.				*/
> GC_API int GC_unregister_my_thread(void);
> 

-- 
--wbr.





More information about the ecl-devel mailing list