Re: Re: Re: my garbage collector sucks

Greg Ewing <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Message-ID <[email protected]>
Mark Hahn <[email protected]>:

> I just realized that in a move you could get in trouble if the GC visited
> the new location, you moved from old to new, then the GC visited the old.
> I'm surprised I haven't seen a problem like this.  I'll have to look into
> why this hasn't happened.  I guess this is the kind of problem you are
> asking about.
> 
> So the short answer is that it is the C programmer's responsibility to make
> sure the object is always linked up.  Note that I am only talking about the
> C coder.  In the Prothon language this is never an issue of course.

It seems to me you can get the same thing happening in Prothon code,
too. Consider the following scenario:

  a = [None]          # 1
  b = [Something()]   # 2
  a[0] = b[0]         # 3
  b[0] = None         # 4

Suppose the main thread has executed lines 1 and 2, and the marker has
got as far as marking objects reachable from list a (of which there
are none) but not list b. Then the marker gets timesliced out and the
main thread executes 3 and 4, moving the Something instance from b to
a. Then the marker marks objects reachable from list b, of which once
again there are none. The marker has now finished its pass without
having marked the Something instance, and erroneously concludes that
it is garbage.

Is there anything to prevent this sort of thing from happening?

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
[email protected]	   +--------------------------------------+
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.