Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 12, 2012 Why won't this compile using DMD? | ||||
---|---|---|---|---|
| ||||
I'm stumped. Can anyone tell me why this won't compule using DMD (v2.060)? It compiles and runs just fine using GDC: import std.stdio; import std.concurrency; shared class Data { public: this(int count) { m_count = count; } int count() const { return m_count; } private: int m_count = void; } int main() { Tid tid = spawn(&threadFunc, thisTid); while (true) { auto data = receiveOnly!(Data); writefln("Count is %s.", data.count); if (data.count == 0) break; } return 0; } void threadFunc(Tid owner) { for (int count = 10; count >= 0; --count) { auto data = new Data(count); send(owner, data); } } The errors I get from DMD are: test.d(27): Error: function test.Data.count () shared const is not callable using argument types () test.d(29): Error: function test.Data.count () shared const is not callable using argument types () /usr/include/dmd/phobos/std/concurrency.d(467): Error: static assert "Aliases to mutable thread-local data not allowed." test.d(41): instantiated from here: send!(Data) |
August 12, 2012 Re: Why won't this compile using DMD? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Trombley | On Sun, 12 Aug 2012 09:39:13 +0200, Ivan Trombley <itrombley@dot-borg.org> wrote: > I'm stumped. Can anyone tell me why this won't compule using DMD (v2.060)? It compiles and runs just fine using GDC: The problems all have to do with one thing - shared class Data does not mean every instance of the class is shared, only that all member functions are. Hence, > auto data = receiveOnly!(Data); should be auto data = receiveOnly!(shared Data); and > auto data = new Data(count); should be auto data = cast(shared)new Data(count); -- Simen |
August 12, 2012 Re: Why won't this compile using DMD? | ||||
---|---|---|---|---|
| ||||
On Sun, Aug 12, 2012 at 7:31 AM, Simen Kjaeraas <simen.kjaras@gmail.com> wrote:
> On Sun, 12 Aug 2012 09:39:13 +0200, Ivan Trombley <itrombley@dot-borg.org>
>> auto data = new Data(count);
>
>
> should be
>
> auto data = cast(shared)new Data(count);
Or
auto data = new shared(Data)(count);
|
August 12, 2012 Re: Why won't this compile using DMD? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | On Sunday, 12 August 2012 at 14:31:37 UTC, Simen Kjaeraas wrote:
> The problems all have to do with one thing - shared class Data does not mean every instance of the class is shared, only that all member functions are.
Excellent, thanks. I assumed that since the class was marked as shared then any instance of it would be as well.
|
August 12, 2012 Re: Why won't this compile using DMD? | ||||
---|---|---|---|---|
| ||||
On Sun, 12 Aug 2012 19:57:16 +0200, José Armando García Sancio <jsancio@gmail.com> wrote: > On Sun, Aug 12, 2012 at 7:31 AM, Simen Kjaeraas <simen.kjaras@gmail.com> wrote: >> On Sun, 12 Aug 2012 09:39:13 +0200, Ivan Trombley <itrombley@dot-borg.org> >>> auto data = new Data(count); >> >> >> should be >> >> auto data = cast(shared)new Data(count); > > Or > auto data = new shared(Data)(count); I thought I'd tried that. Maybe it was auto data = new shared Data(count); -- Simen |
August 12, 2012 Re: Why won't this compile using DMD? | ||||
---|---|---|---|---|
| ||||
On Sun, Aug 12, 2012 at 1:18 PM, Simen Kjaeraas <simen.kjaras@gmail.com> wrote:
> On Sun, 12 Aug 2012 19:57:16 +0200, José Armando García Sancio <jsancio@gmail.com> wrote:
>
>> On Sun, Aug 12, 2012 at 7:31 AM, Simen Kjaeraas <simen.kjaras@gmail.com> wrote:
>>>
>>> On Sun, 12 Aug 2012 09:39:13 +0200, Ivan Trombley <itrombley@dot-borg.org>
>>>>
>>>> auto data = new Data(count);
>>>
>>>
>>>
>>> should be
>>>
>>> auto data = cast(shared)new Data(count);
>>
>>
>> Or
>> auto data = new shared(Data)(count);
>
>
> I thought I'd tried that. Maybe it was
>
> auto data = new shared Data(count);
Someone else may be better able to explain this but "most" D lex token
enclose until the end of the line unless de-marked with a pair of ().
So I think 'new shared Data(count);' becomes 'new
shared(Data(count));'.
|
Copyright © 1999-2021 by the D Language Foundation