POV-Ray : Newsgroups : povray.off-topic : Programming design question, related to GC : Re: Programming design question, related to GC Server Time
1 Oct 2024 07:21:35 EDT (-0400)
  Re: Programming design question, related to GC  
From: Warp
Date: 12 Apr 2008 15:44:08
Message: <48011107@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> As pointed out, this is part of what "weak references" were created for. 
> If a GC runs and the only pointers to an object are "weak", then all the 
> "weak" pointers get set to null, and your Engine can notice that and not 
> try to use that pointer any more.

  If the GC runs in parallel in its own thread, wouldn't there be a mutual
exclusion problem (even in 1-core processors)?

  Let's assume the Engine object does this:

if(listeners[i] != null)
  listeners[i].doSomething();

  If the GC happens to make a sweep after the conditional but before
the call, and it sets the weak reference at listeners[i] to null, we'll
get a null pointer exception (which may seem crazy because we just
checked that it's not null).

  Or are GC engines run only at places where there can't be mutual
exclusion problems? (How does the VM/compiler/interpreter know that?)

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.