[Gc] Thread Local Storage?

Bruce Hoult bruce at hoult.org
Thu Oct 17 22:09:17 PDT 2013


Fundamentally, someone needs to make sure that the thread local storage is
added to the root areas the GC scans pointers from.

Ideally, the standard GC would do that. I don't know what your system is
and therefore whether it is practical for the GC to locate the TLS global
areas.

But you can do it yourself.

There are two approaches:

1) for fixed size areas (or even individual pointer variables) you can
call GC_add_roots(low_address, high_address) on as many areas as necessary.
You can also remove these areas if necessary. Or remove and re-add if they
change size. See gc.h

2) for things that change often during execution, it can be better to point
GC_push_other_roots at your own function, which will be called near the
start of every GC. Your function should call e.g. GC_push_all(bottom, top)
on each appropriate area you want the GC to scan from. Make sure you save
the old value of GC_push_other_roots before installing your function, and
call it too. This is all defined in include/private/gc_priv.h

Unless you see performance problems, it's safer to stick to approach 1).


On Fri, Oct 18, 2013 at 5:20 PM, The Devils Jester <
thedevilsjester at gmail.com> wrote:

> I have a couple of stl containers that hold pointers to classes which
> inherit from gc.  The containers are created via a template that includes
> the gc_allocator.  This has worked great for quite awhile, however I have
> recently made a couple of the containers thread local using __thread.  When
> I do this, however, (while still in my main thread and never having created
> a new thread), at some arbitrary point (maybe when GC kicks in?) my
> container size goes from whatever it was, to zero.
>
>
> I can remove the __thread from the containers and everything works as
> desired, for an indefinite period of time, but adding __thread back in,
> always causes the same issue.  Is there some special initialization I need
> to do to allow for __thread (and similar) to work correctly in the GC?
>
> --
> This message has been scanned for viruses and
> dangerous content by *MailScanner* <https://www.mailscanner.info/>, and is
> believed to be clean.
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> https://www.hpl.hp.com/hosted/linux/mail-archives/gc/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://napali.hpl.hp.com/pipermail/gc/attachments/20131018/cf79daea/attachment.htm


More information about the Gc mailing list