Garbage Collector and Foreign Threads
will75g
will75g at yahoo.it
Mon Mar 19 14:26:11 PDT 2007
If I understand correctly how the D garbage collector works, in order to
work properly it needs to stop every thread before performing collection.
What happens if one or more of the application threads have been created
outside the control of the D runtime? For example imagine a C/C++
application (of which I don't even have the source code) loading a
plug-in written by me in D... Since the D runtime knows only the threads
created in D, the threads created by the C/C++ application could be
still running and calling D code while the D runtime is performing a
collection.
So far the only solution I can think of is suspending the GC while my D
code is called from the C/C++ application.
My fear is that such a solution would lead to a lot of problems. For
example if I have to allocate and release frequently memory, there will
be a point where the D heap is exhausted, since the memory that I
release won't be collected until the GC is enabled again. At that point
every memory allocation will generate a
std.outofmemory.OutOfMemoryException, but there's nothing I can do to
give the collector more memory.
Any idea?
More information about the Digitalmars-d-learn
mailing list