Garbage Collector and Foreign Threads

will75g will75g at yahoo.it
Mon Mar 19 16:19:56 PDT 2007


Daniel Keep wrote:
> So long as the GC knows about all the threads that *do* use GC'ed
> memory, you're fine.

Unfortunately things are not that simple. The two most important threads 
of my plug-in will be an audio processing thread and a GUI thread, both 
created and managed by the hosting application (the host, not my 
plug-in, runs the event loop).

The audio thread isn't really a problem: it's a real-time thread and 
allocating memory inside it is not advisable even when coding with a 
language without GC, so I'm used to that.

The real problem is the GUI thread: I really can't imagine making a GUI 
and all the application logic without resorting on dynamic memory.

The ironic part of this is that if I only had these two threads, there 
wouldn't be any problem, since the audio thread can't allocate or 
dispose memory anyway, while the GUI thread could block for a collection 
without causing any damage.
The real problem is that I need at least another thread, created 
internally by my plug-in, and this thread needs also to allocate memory. 
If a collection is triggered by this third thread, the GC won't be able 
to stop the GUI thread (since it doesn't know it) and that's where I 
foresee problems.


More information about the Digitalmars-d-learn mailing list