>>>>> "t" == ts  <decoux / moulon.inra.fr> writes:

t>  Not really sure, but seems to be a bug in gcc : someone can test it with
t>  another compiler ?

 An example to see the problem (ruby-1.8.0, gcc 3.2 Redhat 8)

 With this modification

svg% diff -u gc.c~ gc.c
--- gc.c~       2003-08-02 08:45:57.000000000 +0200
+++ gc.c        2003-08-30 13:27:39.000000000 +0200
@@ -545,17 +545,21 @@
     return Qfalse;
 }
 
+static int in_locations_array = 0;
+
 static void
 mark_locations_array(x, n)
     register VALUE *x;
     register long n;
 {
+    in_locations_array = 1;
     while (n--) {
        if (is_pointer_to_heap((void *)*x)) {
            rb_gc_mark(*x);
        }
        x++;
     }
+    in_locations_array = 0;
 }
 
 void
@@ -624,6 +628,12 @@
     if (rb_special_const_p(ptr)) return; /* special const not marked */
     if (obj->as.basic.flags == 0) return;       /* free cell */
     if (obj->as.basic.flags & FL_MARK) return;  /* already marked */ 
+    if (!is_pointer_to_heap((void *)ptr)) {
+       fprintf(stderr, "error : in_locations_array %d -- ptr 0x%x -- heaps 0x%x\n",
+               in_locations_array, ptr, heaps);
+       exit(1);
+    }
+    in_locations_array = 0;
     obj->as.basic.flags |= FL_MARK;
 
     CHECK_STACK(ret);
svg% 

svg% cat b.rb
#!/usr/bin/ruby
thread_block= Proc.new do
   1.upto(20000) do
      a = {1=>12}
   end
  Thread.new &thread_block
end

1.upto(120) do |i|
   Thread.new &thread_block
end
p "END"
Thread.stop
svg% 

svg% ./ruby b.rb
error : in_locations_array 1 -- ptr 0x80e6898 -- heaps 0x80e6898
svg% 


 This mean that rb_gc_mark() is called from mark_locations_array() with the
 value 0x80e6898. But mark_locations_array() can't call it with the value
 0x80e6898 because is_pointer_to_heap() is false.

 I see, actually, only one explanation :
   * is_pointer_to_heap() is called with the right value (in
     mark_locations_array()) 
   * a *modified* value is given to rb_gc_mark()

 Now ruby will do

   obj->as.basic.flags |= FL_MARK;

 this means that heaps[0] is modified, and at this step the GC can't work.


Guy Decoux