[gclist] Boehm's GC and multi-threaded libraries

Hans Boehm boehm@hoh.mti.sgi.com
Tue, 21 Jan 1997 18:28:42 -0800


I work for SGI, but I don't know anything about the ImageVision libraries
beyond what I could determine from a few minutes of glancing at the man pages.

In general, you have several options with the collector and multithreaded
libraries:

1. Find a collector that supports the right kind of threads and allocate
everything through the collector.  I remember that somebody was working on an
sproc threads port, so this may be feasible here, but it's
probably not necessary.  This may also not yield optimal performance.
You want to avoid allocating large bitmaps through the collector
if you can easily avoid it.  At a minimum, you want to inform the collector
that they should not be scanned.  In performance-sensitive cases you do want
to manage them explicitly when possible, since large allocations greatly
increase GC frequency, and are hence expensive.  (I don't actually know
what kind of threads the library uses, but I would also guess it's sproc
threads.  There may or may not be plans to convert it to pthreads.)

2. Arrange that the collector is only invoked from the one active thread that
might have pointers to garbage collected memory.  It sounds to me like
Dean's observation to avoid REDIRECT_MALLOC is close to sufficient in this
case.
You do have to be careful that you do not pass essential pointers to garbage
collected data to the library, if the library expects the data to outlive
the call.  I would guess that's easy in this case.

There is a potential performance issue, in that it sounds like the library
is likely to allocate very large pointerfree objects.  Depending on exactly
how they are allocated, they may or may not get scanned by the collector
even if they're not allocated through it.
It may take a long time to scan them.  (This all has to do with dynamic library
handling.)  If you do find a problem of this sort, let me know.  It should be
easy to get around.  This is something I would like to address in the next
version anyway.

Hans

On Jan 13,  7:18pm, Dean Brettle wrote:
> Subject: [gclist] Boehm's GC and multi-threaded libraries
> Hi all,
>
> I am new to the list and GC in general. So please forgive me if this
> question is inappropriate.
>
> We are considering using Boehm's GC for a project which will run under
> IRIX 6.2.  The code we will be writing will not be multi-threaded,
> however we do plan to use SGI's ImageVision libraries.  These libraries
> can "transparently" take advantage of multi-processor SGI platforms,
> presumably using sproc threads.  The question is:
>
> Assuming the threads only exist during calls into the libraries, can we
> safely use Boehm's GC in _incremental_ mode for our classes?
>
> The README.sgi indicates that "sproc threads are not supported" and
> "pthreads are somewhat somewhat supported without incremental
> collection", but I'm not sure if these apply if the threads exist only
> in libraries.  I'm betting the answer is something like:
>
> It will work fine as long as we don't use -DREDIRECT_MALLOC because if
> we use -DREDIRECT_MALLOC, any malloc's in the library will call the GC
> in a multi-threaded environment.  Is this right?
>
> TIA,
>
> --Dean
>-- End of excerpt from Dean Brettle



-- 
Hans-Juergen Boehm
boehm@mti.sgi.com