[Gc] GC crashes in GC_mark_from when running on custom stack
rototor at rototor.de
Thu Mar 10 15:25:23 PST 2005
I'm using BoehmGC 6.3. In my program I've got some objects which run in a
"scheduler". The objects should behave like tasks in a cooperate
multitasiking environment. I.e. it is possible that one object "sleeps" and
should return later to continue. The other objects should of course
continue to run. I think this is called a continuation.
I implemented this in the following way:
- Allocate a new execution stack using GC_malloc()
- Switch the stack using x86 asm to this new stack and run the objects
method on it
- If the object finishes the run, reuse the stack for the next object
- If the object goes to sleep, store the current esp/eip for later
continuation, switch back to the original stack, allocate a new execution
stack and then continue with the next object
- Later the continuations are continued when they are ready. The stack/eip
is switched back and the objects method continues.
This all works well, but sometimes I get a crash in GC_mark_from when memory
is allocated while the program is on the custom stack and the GC decides to
collect a little.
It crashes in this line:
deferred = *limit;
#0 0xb7fb1dfa in GC_mark_from (mark_stack_top=0x807a0a0,
mark_stack=0x80780a8, mark_stack_limit=0x80800a8) at mark.c:759
#1 0xb7fb16b8 in GC_mark_some (cold_gc_frame=0x8236d38 "") at mark.c:361
#2 0xb7fab665 in GC_stopped_mark (stop_func=0xb7faad1c
<GC_never_stop_func>) at alloc.c:520
#3 0xb7fab2b4 in GC_try_to_collect_inner (stop_func=0xb7faad1c
<GC_never_stop_func>) at alloc.c:367
#4 0xb7fac0c6 in GC_collect_or_expand (needed_blocks=1, ignore_off_page=0)
#5 0xb7fac30d in GC_allocobj (sz=256, kind=0) at alloc.c:1073
#6 0xb7fb7283 in GC_generic_malloc_inner (lb=924, k=0) at malloc.c:136
#7 0xb7fb739d in GC_generic_malloc (lb=924, k=0) at malloc.c:192
#8 0xb7fb7564 in GC_malloc_atomic (lb=924) at malloc.c:262
Is there a way to tell the GC that the stack was switched and what the new
stack is, so that it doesn't crash? Or is this is a bug in the GC?
Or should I just disable the GC using GC_enable()/GC_disable() while the
program runs on the custom stack?
More information about the Gc