shared and cryptic error messages

Jose Armando Garcia jsancio at gmail.com
Thu Mar 31 12:18:28 PDT 2011


First of all, thanks for the reply.

That means that it is imposible to use a struct or class that
overrides ~this() inside of a synchronized class. As long as I take
the extra care of making sure that I don't expose an object of this
class/struct outside of the synchronized class. It is impossible
because the compiler is responsible of calling ~this() so how can I
cast it to a non-shared object?

I really like D and its design but I it is hard to use in its current
state. At this point I am only writing toy applications and have
encounter many bugs. For example the following segfaults:

File[int] writers;
writers[1] = File("filename", "w");

I don't have the code infront of me but it segfaults in File.opAssign.
It makes sense that opAssign gets called on 'writers[1] =' but after
investigation, 'writers[1]' was never fully constructed (default ctor
was never called).

On Wed, Mar 30, 2011 at 7:34 PM, Jason House
<jason.james.house at gmail.com> wrote:
> he compiler wants "argument types () shared" instead of "argument types ()". It's an awful error message, and I'm certain I filed a bug for it at least a year ago. In the toy example, mark the destructor as shared, and it should compile.
>
> Jose Armando Garcia Wrote:
>
>> It looks like the following works:
>>
>> struct B {}
>> synchronized class A { private B b }
>>
>> but this doesn't:
>>
>> struct B { ~this() {} }
>> synchronized class A { private B b }
>>
>> On Wed, Mar 30, 2011 at 4:59 PM, Jose Armando Garcia <jsancio at gmail.com> wrote:
>> > import std.stdio;
>> >
>> > class B
>> > {
>> >  private File file;
>> > }
>> > synchronized class A
>> > {
>> >  private File file;
>> > }
>> >
>> > void main()
>> > {
>> > }
>> >
>> > /usr/include/d/dmd/phobos/std/stdio.d(292): Error: destructor
>> > std.stdio.File.~this () is not callable using argument types ()
>> >
>> > Why am I getting this error? I suspect that synchronized is the
>> > problem. How do I get around this error? Does this mean that
>> > synchronized classes are not allowed to have as member
>> > unsynchronized/regular classes? Has anyone tried to write a
>> > multithreaded application using D? Why is the error showing up in
>> > std/stdio.d and not in my file? Can anyone point me to a decent
>> > documentation of how "shared" works? I have read chapter 13 of The D
>> > Programming Language and it is not sufficient for the level of
>> > understanding I seek.
>> >
>> > That is a lot of question. Hopefully I get answer to at least one.
>> >
>
>


More information about the Digitalmars-d mailing list