On Monday, January 19, 2004, at 06:37 , Gordon Henriksen wrote:

Dan Sugalski wrote:

For a copying collector to work, all the mutators must be blocked,
and arguably all readers should be blocked as well.

True of non-moving collectors, too. [...]


Some of what I've written up addresses why. [...] I'll send that section when I get out of the office.

Consider this simple object graph:


Root set = { &A, &B }

    [ A=NULL]
    [ B=&C  ] ---> [ C=....]

Collection begins in thread 1 and marks A as reachable before being preempted by thread 2:

    [xA=NULL]
    [ B=&C  ] ---> [ C=....]

Thread 2 sets A to &C, and nullifies B before being preempted again by thread 1:

    [xA=&C  ] ---> [ C=....]
    [ B=NULL]

Thread 1 marks B as reachable:

    [xA=&C  ] ---> [ C=....]
    [xB=NULL]

The mark phase complete, thread 1 sweeps:

    [ A=&???] ---> ???
    [ B=NULL]

C was not marked reachable (although it was) and was thus erroneously collected, leaving a dangling pointer. This problem applies equally to copying and mark-sweep collectors.



Gordon Henriksen
[EMAIL PROTECTED]



Reply via email to