Re: GC and Coroutines]
Paul Bone <[email protected]>
| Newsgroups | gmane.comp.programming.garbage-collection.boehmgc |
|---|---|
| Message-ID | <20140129235722.GJ901@durif> |
On Tue, Jan 28, 2014 at 10:12:11AM -0300, Juan Wajnerman 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? > Mercury (http://www.mercurylang.org) uses Boehm GC and multiple stacks. We allocate stack memory from Boehm GC and ensure that the stack memory is reachable through some other heap structures. This is probably a little bit more feasable since we don't have to make these stacks compatible with C code, (we could manipulate C's stack pointer but we don't). The drawback is that when the GC needs to do a collection, and the current stack frame is roughly in the middle of the allocated stack memory, then the GC will scan the whole stack, not just the area from the top down to and including the stack frame (stacks grow downwards). One solution to this is to use a segmented stack. This also has other benifits but it also requires a mechanism that tests to see if we need to allocate more memory. These mechanisms can slow things down (checking when allocating every non-leaf stack frame) or not always portable and a little wasteful of memory (redzone), the redzone might also annoy Boehm GC. Hope this helps. -- Paul Bone http://www.bone.id.au