Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 26, 2010 Threading errors. | ||||
---|---|---|---|---|
| ||||
Hello. I am working through Alexandrescu's "The D Programming Language". He has an example in his concurrency chapter which I can't compile. It looks to be missing a few import packages, but getting over that, I still can't get the example to work: import std.concurrency, std.stdio; import std.contracts, std.typecons; /* I added this */ void main() { auto low = 0, high = 25; auto tid = spawn(&writer); foreach( i; low .. high) { writeln("Main thread: ", i); tid.send(thisTid, i); enforce( receiveOnly!Tid() == tid); } return; } void writer() { for( ;; ) { auto msg = receiveOnly!(Tid, int)(); writeln( "Secondary thread: ", msg[1]); msg[0].send(thisTid); } return; } I get the following compiler error: $ dmd Thread2.d Thread2.d(10): Error: template std.typecons.Tuple!(Tid).Tuple.opEquals(T) if (is(typeof(T.field))) does not match any function template declaration Thread2.d(10): Error: template std.typecons.Tuple!(Tid).Tuple.opEquals(T) if (is(typeof(T.field))) cannot deduce template function from argument types !()(Tid) $ dmd --help Digital Mars D Compiler v2.042 Copyright (c) 1999-2010 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html So, what am I doing wrong here? thanks. |
July 26, 2010 Re: Threading errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dcoder | On 26.07.2010 19:45, dcoder wrote: > Hello. > > [snip] > $ dmd --help > Digital Mars D Compiler v2.042 > Copyright (c) 1999-2010 by Digital Mars written by Walter Bright > Documentation: http://www.digitalmars.com/d/2.0/index.html > > > I suggest updating compiler - it's should be 2.047 now. The outdated distribution could also feature some bugs in std.concurency. > So, what am I doing wrong here? > > thanks. > > -- Dmitry Olshansky |
July 26, 2010 Re: Threading errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dmitry Olshansky | Dmitry Olshansky wrote:
> On 26.07.2010 19:45, dcoder wrote:
>> Hello.
>>
>>
> [snip]
>> $ dmd --help
>> Digital Mars D Compiler v2.042
>> Copyright (c) 1999-2010 by Digital Mars written by Walter Bright
>> Documentation: http://www.digitalmars.com/d/2.0/index.html
>>
>>
>>
> I suggest updating compiler - it's should be 2.047 now. The outdated distribution could also feature some bugs in std.concurency.
>> So, what am I doing wrong here?
>>
>> thanks.
>>
>>
>
>
Doesn't work for 2.047 either.
dthreadpass.d(19): Error: no [] operator overload for type Tuple!(Tid,int)
dthreadpass.d(20): Error: no [] operator overload for type Tuple!(Tid,int)
|
July 26, 2010 Re: Threading errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rory Mcguire | == Quote from Rory Mcguire (rjmcguire@gm_no_ail.com)'s article > Dmitry Olshansky wrote: > > On 26.07.2010 19:45, dcoder wrote: > >> $ dmd --help > >> Digital Mars D Compiler v2.042 > >> Copyright (c) 1999-2010 by Digital Mars written by Walter Bright > >> Documentation: http://www.digitalmars.com/d/2.0/index.html > >> > >> > >> > > I suggest updating compiler - it's should be 2.047 now. The outdated distribution could also feature some bugs in std.concurency. > Doesn't work for 2.047 either. > dthreadpass.d(19): Error: no [] operator overload for type Tuple!(Tid,int) > dthreadpass.d(20): Error: no [] operator overload for type Tuple!(Tid,int) Yep, I get that same error after upgrading my compiler. $ dmd --help Digital Mars D Compiler v2.047 Copyright (c) 1999-2010 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html thanks. |
July 26, 2010 Re: Threading errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dcoder Attachments:
| On Mon, Jul 26, 2010 at 19:11, dcoder <dcoder@devnull.dev> wrote:
> == Quote from Rory Mcguire (rjmcguire@gm_no_ail.com)'s article
> > Dmitry Olshansky wrote:
>
std.typecons.Tuple fields cannot be indexed like arrays, Andrei made a mistake. To access field #n, use ._n or .field[n]. There is no difference between the two.
void writer() {
for( ;; ) {
auto msg = receiveOnly!(Tid, int)(); // msg is a Tuple!(Tid, int), msg._0
is a Tid, msg._1 is an int.
writeln( "Secondary thread: ", msg._1);
msg._0.send(thisTid);
}
}
Also, in my case, the return; in writer must be commented out, or DMD complains it cannot be reached.
Philippe
|
July 27, 2010 Re: Threading errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | Philippe Sigaud wrote:
> On Mon, Jul 26, 2010 at 19:11, dcoder <dcoder@devnull.dev> wrote:
>
>> == Quote from Rory Mcguire (rjmcguire@gm_no_ail.com)'s article
>> > Dmitry Olshansky wrote:
>>
>
>
> std.typecons.Tuple fields cannot be indexed like arrays, Andrei made a mistake. To access field #n, use ._n or .field[n]. There is no difference between the two.
>
> void writer() {
> for( ;; ) {
> auto msg = receiveOnly!(Tid, int)(); // msg is a Tuple!(Tid, int),
> msg._0
> is a Tid, msg._1 is an int.
> writeln( "Secondary thread: ", msg._1);
> msg._0.send(thisTid);
> }
> }
>
> Also, in my case, the return; in writer must be commented out, or DMD complains it cannot be reached.
>
>
> Philippe
Interesting, I didn't have to comment out return; using dmd 2.047 on linux
|
July 27, 2010 Re: Threading errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rory Mcguire Attachments:
| On Tue, Jul 27, 2010 at 11:25, Rory Mcguire <rjmcguire@gm_no_ail.com> wrote: > > > Also, in my case, the return; in writer must be commented out, or DMD complains it cannot be reached. > > > Interesting, I didn't have to comment out return; using dmd 2.047 on linux > I think I have -w (warnings treated as errors?) always checked. That's my Code::Blocks default configuration for DMD. I was on Windows for this test. I never cheked if there was any difference between OSes for this :-) |
July 27, 2010 Re: Threading errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | Philippe Sigaud wrote:
> On Tue, Jul 27, 2010 at 11:25, Rory Mcguire <rjmcguire@gm_no_ail.com> wrote:
>
>>
>> > Also, in my case, the return; in writer must be commented out, or DMD complains it cannot be reached.
>>
>
>
>>
>> Interesting, I didn't have to comment out return; using dmd 2.047 on linux
>>
>
> I think I have -w (warnings treated as errors?) always checked. That's my
> Code::Blocks default configuration for DMD.
> I was on Windows for this test. I never cheked if there was any difference
> between OSes for this :-)
:) thanks Philippe
|
July 27, 2010 Re: Threading errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rory Mcguire | == Quote from Rory Mcguire (rjmcguire@gm_no_ail.com)'s article
> Philippe Sigaud wrote:
> >> > Also, in my case, the return; in writer must be commented out, or DMD complains it cannot be reached.
> >>
> >
> >
> >>
> >> Interesting, I didn't have to comment out return; using dmd 2.047 on linux
> >>
> >
> > I think I have -w (warnings treated as errors?) always checked. That's my
> > Code::Blocks default configuration for DMD.
> > I was on Windows for this test. I never cheked if there was any difference
> > between OSes for this :-)
> :) thanks Philippe
Actually, after making the changes that you suggest, Philippe my program works. Thanks.
However, I did not have to comment out the return statement. But when I did compile using the -w flag, I do get the compiler error that you describe.
Anyways, thanks for the coding suggestion.
|
Copyright © 1999-2021 by the D Language Foundation