digitalmars.D - Why won't this compile using DMD?
- Ivan Trombley (46/46) Aug 12 2012 I'm stumped. Can anyone tell me why this won't compule using DMD
- Simen Kjaeraas (13/17) Aug 12 2012 The problems all have to do with one thing - shared class Data does
- Ivan Trombley (3/6) Aug 12 2012 Excellent, thanks. I assumed that since the class was marked as
- =?ISO-8859-1?Q?Jos=E9_Armando_Garc=EDa_Sancio?= (3/7) Aug 12 2012 Or
- Simen Kjaeraas (8/20) Aug 12 2012 On Sun, 12 Aug 2012 19:57:16 +0200, Jos=C3=A9 Armando Garc=C3=ADa Sancio...
- =?ISO-8859-1?Q?Jos=E9_Armando_Garc=EDa_Sancio?= (6/27) Aug 12 2012 Someone else may be better able to explain this but "most" D lex token
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)
Aug 12 2012
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); andauto data = new Data(count);should be auto data = cast(shared)new Data(count); -- Simen
Aug 12 2012
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.
Aug 12 2012
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>Or auto data = new shared(Data)(count);auto data = new Data(count);should be auto data = cast(shared)new Data(count);
Aug 12 2012
On Sun, 12 Aug 2012 19:57:16 +0200, Jos=C3=A9 Armando Garc=C3=ADa Sancio= = <jsancio gmail.com> wrote:On Sun, Aug 12, 2012 at 7:31 AM, Simen Kjaeraas <simen.kjaras gmail.co=m> =wrote:On Sun, 12 Aug 2012 09:39:13 +0200, Ivan Trombley =I thought I'd tried that. Maybe it was auto data =3D new shared Data(count); -- = Simen<itrombley dot-borg.org>Or auto data =3D new shared(Data)(count);auto data =3D new Data(count);should be auto data =3D cast(shared)new Data(count);
Aug 12 2012
On Sun, Aug 12, 2012 at 1:18 PM, Simen Kjaeraas <simen.kjaras gmail.com> wr= ote:On Sun, 12 Aug 2012 19:57:16 +0200, Jos=E9 Armando Garc=EDa Sancio <jsancio gmail.com> wrote: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));'.On Sun, Aug 12, 2012 at 7:31 AM, Simen Kjaeraas <simen.kjaras gmail.com> wrote:I thought I'd tried that. Maybe it was auto data =3D new shared Data(count);On Sun, 12 Aug 2012 09:39:13 +0200, Ivan Trombley <itrombley dot-borg.org>Or auto data =3D new shared(Data)(count);auto data =3D new Data(count);should be auto data =3D cast(shared)new Data(count);
Aug 12 2012









"Ivan Trombley" <itrombley dot-borg.org> 