Signals & Slots
Sean Kelly
sean at f4.ca
Mon Nov 5 12:19:38 PST 2007
Bill Baxter wrote:
> David B. Held wrote:
>> I know much has been said about this topic over the years, and several
>> libraries have been written. Can anyone summarize the state of the
>> art for S&S in D? I know there is a std.signals, but I can see that
>> it is not the end of the story...
>
> I'd like to know what the current story is too, both in Phobos and
> Tango. Mainly I mean the current story with regard to weak references.
Tango does not currently support weak references. This was a deliberate
decision on my part because I do not feel that weak references are
compatible with garbage collection in D. In a multithreaded program,
the only way to safely use the callback mechanism built to support the
weak reference concept is by using lock-free programming (using
synchronized blocks instead is a sure way to deadlock an application
when using "stop the world" collections). However, lock-free
programming is quite complicated and utterly non-portable, given its
reliance on specialized knowledge of the target memory model.
Therefore, I can't rationalize adding a feature that is so prone to
error and misuse unless it provides an extremely compelling reason for
its presence. And I'll admit that I question the point of needing the
weak reference feature for S&S in the first place. I feel that doing so
encourages bad programming style, and frankly, I can't envision a
programming model that requires it anyway. But then I'm not a Qt
person, so perhaps someone could explain the need for this to me?
If it's any consolation, the Tango/Phobos merger will basically require
that weak reference support be added to the runtime unless Phobos
decides this feature is no longer necessary. So my opinion in the
matter may ultimately be rendered unimportant. Unfortunately, this will
complicate the means by which object monitors are overridden in Tango,
but I don't think there's any way around this.
Sean
More information about the Digitalmars-d
mailing list