Re: GC and Coroutines

Kjetil Matheussen <[email protected]>
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <CAC6niEK1DS5mWgi-+=srpyzO5cnHzTnQHoRVs5E-qeShR5BHrQ@mail.gmail.com>
On Tue, Jan 28, 2014 at 2:12 PM, Juan Wajnerman <[email protected]> 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.
https://github.com/kmatheussen/snd-rt/blob/master/rt-coroutines.scm

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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.