[Issue 4621] Destructors are inherently un- at safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 12 08:10:21 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4621



--- Comment #15 from nfxjfg at gmail.com 2010-08-12 08:10:19 PDT ---
(In reply to comment #14)
> Beside, is it worth it? I mean, what is the use of a resurrected object beyond
> providing a little more safety? Given the multithreading model, we know
> finalizers can't be made safe; them being half-safer doesn't bring us much.

If you'd move finalizer execution to a dedicated finalizer thread, it'd be
already quite safe. Then you can acquire locks to do synchronized access to
your data.

But it still doesn't fit in D2's typesystem.

> Well, the object's memory block itself is no longer referenced by other threads
> (otherwise it would not be collected), so I guess as long as you only access
> values inside this memory block you're safe. You can probably also access
> non-GC memory you're the sole owner of, or non-GC shared memory. But you
> shouldn't access non-shared globals, or non-shared memory that someone else
> could have a reference to. This is starting to be really complicated, but
> except for the non-GC memory part it looks quite similar to the restrictions
> applied to methods of a synchronized class.

Running on a different thread still makes a severe difference to shared or C
data. C APIs usually aren't thread-safe. For some OS APIs, the caller thread
makes a difference (for instance, you'd break OS provided TLS).

You'll have to make an explicit exception in the language spec for finalizers
to allow this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list