[Gc] GC and Coroutines

Kjetil Matheussen k.s.matheussen at gmail.com
Tue Jan 28 05:53:33 PST 2014

On Tue, Jan 28, 2014 at 2:12 PM, Juan Wajnerman <jwajnerman at manas.com.ar> wrote:
> I'm trying to use the GC together with this coroutine library:
> http://xmailserver.org/pcl.html
> But when the GC tries to free some memory running inside a coroutine it
> crashes.
> I guess the problem happens because other coroutine stacks are inaccessible
> during coroutine execution but I don't know how to fix this.
> Does anyone have some tips or tell me at least how could I debug this issue?

The snd-rt audio programming system also uses pcl for coroutines.
The way to snd-rt adds pcl stacks to the gc roots is simply to do it manually.

The following function can be used to get the high value:
(this method assumes stack grows down)

(<nonstatic-void> rt_set_stack_high_value (lambda
((<struct-rt_coroutine*> coroutine))
  (<int> dummy)
  (set! coroutine->stack_high &dummy))))

and then you can add stacks manually to the garbage collector by doing
something like this: GC_add_root(coroutine->stack_high + 1024,
coroutine->stack_high - STACK_SIZE);

There's probably more elegant ways to do it though.

More information about the Gc mailing list