Re[2]: [Gc] (Win32) attempt to unregister first GC thread will cause acrash.

Ivan Maidanski ivmai at mail.ru
Thu Dec 17 00:21:12 PST 2009


Hi!
"Boehm, Hans" <hans.boehm at hp.com> wrote:
> Under normal circumstances, this shouldn't be an issue, right?  The structure for the main thread should be statically allocated when the GC is initialized.  And GC_unregister_my_thread() shouldn't be called on the main thread.
>
> The patch looks fine.  I just wonder whether there is correct client code that really needs it.
>
> Hans
>
> > -----Original Message-----
> > From: gc-bounces at napali.hpl.hp.com
> > [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of
> > Jean-Claude Beaudoin
> > Sent: Wednesday, December 16, 2009 4:30 AM
> > To: gc at napali.hpl.hp.com
> > Subject: [Gc] (Win32) attempt to unregister first GC thread
> > will cause a crash.
> >
> >
> > Hello BDW-GC maintainers,
> >
> > In file win32_threads.c there is a special case for the
> > static allocation of the first GC_thread structure.
> >
> > If someone calls GC_unregister_my_thread() on that very first
> > GC thread there will be a segmentation violation inside
> > GC_delete_thread() when it tries to call GC_INTERNAL_FREE().

The docs cleanly say it's not allowed:

/* Unregister the current thread.  Only an explicity registered thread  */
/* (i.e. for which GC_register_my_thread() returns GC_SUCCESS) is       */
/* allowed (and required) to call this function.  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.  Must not be called inside  */
/* a GC callback function (except for GC_call_with_stack_base() one).   */
GC_API int GC_CALL GC_unregister_my_thread(void);

The rule is: if you registered a thread then you, nobody else, are allowed and obliged to unregister it.
The primordial thread is registered by the collector itself, so if someone calls C_register_my_thread() in it, the returned value would not be GC_SUCCESS.

Of course, we may change the docs and the behavior, but is it worth (as Hans asked above)?

> >
> > I attached to this message a patch against 7.2alpha4 that
> > seems to fix the problem.
> >
> > Cheers,
> >
> > Jean-Claude Beaudoin

Bye.


More information about the Gc mailing list