Thread overview
GC and realtime threads.
Jul 12, 2006
chrisk
Jul 13, 2006
Frank Benoit
Jul 13, 2006
Hasan Aljudy
Jul 13, 2006
Frank Benoit
Jul 13, 2006
Boris Wang
July 12, 2006
I'm interested in trying D for writing some audio fx plugins. Basicly the plugin would be a dll with 2 threads, a GUI and an Audio thread. Is it posible to prevent the GC from running during the audio thread? Can the audio thread stop the CG? As the dll will be loaded into a host application does that mean the GC will halt the all dll and application threads while it runs?

thanks,

chris


July 13, 2006
chrisk wrote:
> I'm interested in trying D for writing some audio fx plugins. Basicly the plugin would be a dll with 2 threads, a GUI and an Audio thread. Is it posible to prevent the GC from running during the audio thread? Can the audio thread stop the CG? As the dll will be loaded into a host application does that mean the GC will halt the all dll and application threads while it runs?
> 
> thanks,
> 
> chris 
> 

You can control the GC via the 'std.gc' import, which exposes the 'std.gc.disable()' and 'std.gc.enable()' functions for turning automatic collection off/on, and the 'std.gc.fullCollect()' function for manually initiating a collection run.

See: http://digitalmars.com/d/phobos/std_gc.html

As far as I know, in the case of cross-language DLL's (I assume the program you're writing the plugin for is not in D itself), the GC will only pause the DLL's own threads, but I could be wrong.

-- Chris Nicholson-Sauls
July 13, 2006

chrisk wrote:
> I'm interested in trying D for writing some audio fx plugins. Basicly the plugin would be a dll with 2 threads, a GUI and an Audio thread. Is it posible to prevent the GC from running during the audio thread? Can the audio thread stop the CG? As the dll will be loaded into a host application does that mean the GC will halt the all dll and application threads while it runs?
> 
> thanks,
> 
> chris 
> 
> 

Well, you could disable the GC, but I think you lose a lot of D Power by doing that.
You can manually delete objects/arrays when you know you're not going to use them anymore, even when the GC is enabled.

I'm not familiar at all with audio programming, but I think you can design your code such that there is always very little garbage, while leaving the GC running in the background, to clean any garbage you might have forgotten to clean manually.
Maybe calling std.gc.fullCollect() everynow and then (while there is still little garbage) may help in this case.

However, all of that is a bunch of wild guesses off the top of my head. I haven't tested any of it and I don't know if it eliminates any pauses caused by the GC or not.
July 13, 2006
> You can control the GC via the 'std.gc' import, which exposes the
> 'std.gc.disable()' and 'std.gc.enable()' functions for turning automatic
> collection off/on, and the 'std.gc.fullCollect()' function for manually
> initiating a collection run.
> 

disable and enable is not implemented. See dmd/src/phobos/internal/gc/gcx.d Search for the use of the 'disabled' variable.
July 13, 2006
chrisk schrieb:
> I'm interested in trying D for writing some audio fx plugins. Basicly the plugin would be a dll with 2 threads, a GUI and an Audio thread. Is it posible to prevent the GC from running during the audio thread? Can the audio thread stop the CG? As the dll will be loaded into a host application does that mean the GC will halt the all dll and application threads while it runs?
> 
> thanks,
> 
> chris
> 
> 

The actual implementation of the phobos GC is triggered every time you
allocate new memory. This happens if you call 'new', increase the size
of an array, use '~' or use code which does this. If your thread is only
a little piece of code, you can perhaps write it, not using any allocation.

Interrupting the GC is possible, but it is a risk. You must be sure not to manipulate memory in a way that affects the GC. (No allocations, no moving of references ) If you are sure it doesn't you need a way to reactivate your thread. An OS timer? The GC uses the Thread.pauseAll. You can use resume or just run in the OS callback?
July 13, 2006
ErLang's GC can support soft-real-time applicaitons.

Has no information about D's GC.


"chrisk" <not@here.com> дÈëÏûÏ¢ÐÂÎÅ:e940bv$2rup$1@digitaldaemon.com...
> I'm interested in trying D for writing some audio fx plugins. Basicly the plugin would be a dll with 2 threads, a GUI and an Audio thread. Is it posible to prevent the GC from running during the audio thread? Can the audio thread stop the CG? As the dll will be loaded into a host application does that mean the GC will halt the all dll and application threads while it runs?
>
> thanks,
>
> chris
>
>