[Gc] GC and Coroutines

Kjetil Matheussen k.s.matheussen at gmail.com
Tue Jan 28 13:48:44 PST 2014


On Tue, Jan 28, 2014 at 10:35 PM, Juan Wajnerman
<jwajnerman at manas.com.ar> wrote:
> I made the stack and the coroutine variables (might be the same value, right?) as global but it still crashes.
> Something I noticed is that when I call co_create() without a stack (it allocates its own stack) it works fine if I didn't call GC_malloc() before.
> In other words, it crashes if I call GC_malloc() in the main function.
>

To be honest, I didn't use BDW-GC with libpcl, but a different
conservative garbage collector.
It should have worked with the garbage collector I used.

Why BDW-GC fails here, I don't know, but the stack trace below might
give someone
with more knowledge about BDW-GC an idea:


(gdb) bt
#0  0x0000000000419b00 in GC_push_all_eager ()
#1  0x0000000000419b5c in GC_push_all_stack ()
#2  0x000000000040570c in GC_push_all_stack_sections ()
#3  0x000000000040c323 in GC_push_all_stacks ()
#4  0x0000000000408561 in GC_default_push_other_roots ()
#5  0x00000000004058bc in GC_push_roots ()
#6  0x0000000000417ed8 in GC_mark_some ()
#7  0x000000000040ea9f in GC_stopped_mark ()
#8  0x000000000040e71a in GC_try_to_collect_inner ()
#9  0x000000000040fae3 in GC_collect_or_expand ()
#10 0x000000000040fdfb in GC_allocobj ()
#11 0x0000000000415d4e in GC_generic_malloc_inner ()
#12 0x0000000000415efa in GC_generic_malloc ()
#13 0x0000000000416334 in GC_core_malloc ()
#14 0x000000000040a2a4 in GC_malloc ()
#15 0x0000000000404a63 in real_coroutine_body (sbase=0x6bff90,
realarg=0x6b8000) at test2.c:12
#16 0x000000000040708c in GC_call_with_stack_base ()
#17 0x0000000000404a97 in coroutine_stub (arg=0x0) at test2.c:21
#18 0x000000000041ada5 in co_runner ()
#19 0x0000003b49446370 in ?? () from /lib64/libc.so.6
#20 0x0000000000000000 in ?? ()
(gdb)


>
> On Jan 28, 2014, at 6:16 PM, Kjetil Matheussen <k.s.matheussen at gmail.com> wrote:
>
>> On Tue, Jan 28, 2014 at 9:36 PM, Juan Wajnerman <jwajnerman at manas.com.ar> wrote:
>>> I'm not sure if I understand how I'm supposed to use the GC_stack_base info.
>>> I tried to call GC_add_root using the mem_base but with no luck so far.
>>>
>>> Here is a small example of what I'm trying to run:
>>> https://gist.github.com/waj/8675658
>>> In my machine it crashes after 60 or 70 iterations.
>>>
>>> The stack space allocated for the coroutine is also allocated with the GC so
>>> it shouldn't be necessary to register that area, right?
>>>
>>
>> Yes, but I think the problem with your example is
>> that  the pointer to the stack variable in main is not
>> tracable inside the coroutine. To test that theory,
>> it should work if you just make it into a global variable.
>>
>> If you run more coroutines, you also need to add
>> the context of them to the GC roots.
>>
>> For my program, it was enough just doing this:
>>
>> coroutine_t c
>> GC_add_root(c, c+ MAX(sizeof(ucontext_t), sizeof(jmp_buf)))
>
>
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/


More information about the Gc mailing list