[self-interest] simplicity
Toby Ovod-Everett
toby at ovod-everett.org
Wed Jun 30 04:25:22 UTC 2004
On Tue, Jun 29, 2004 at 08:23:00PM +1000, Steven Shaw wrote:
> On Monday 28 June 2004 15:54, Toby Ovod-Everett wrote:
> > On Sun, Jun 27, 2004 at 08:20:43PM -0700, Michael Latta wrote:
> > when writing multi-threaded code that I have to worry about race
> > conditions. But my instinct is to presume that in single-threaded code
> > that I can forget about them, and that is no longer the case when
> > deterministic finalization goes out the window.
>
> But surely not unless you're going to have a finalisation method (this assumes
> that the finalisation will be done on another thread - probably the gc
> thread). If you write single threaded code and have no need for finalisation
> then you still don't need to worry about race-conditions/non-determinism.
For instance, say I have a class that interacts with the Windows registry. In
one block, I access a key and read through its values. The block closes and
then I go to delete the key. If the finalizer for the object that interacts
with the key doesn't run before I attempt to delete the key, I will have
problems because the Windows registry system won't allow deletion of a key for
which there are open handles. The requirement that I always explicitly close
objects to ensure that finalizers run immediately begins to look an awful lot
like the requirement that I hand back malloc'ed memory . . . :)
--Toby Ovod-Everett
More information about the Self-interest
mailing list