digitalmars.D.learn - Problems with receive
- Bob Cowdery (36/37) Aug 29 2010 Hi
- Stanislav Blinov (5/51) Aug 29 2010 I'm not sure about Variant part yet (never tried it myself), but as for
- Stanislav Blinov (8/10) Aug 29 2010 Hmm, after some inspection I can say this is an implementation issue.
- Bob Cowdery (6/16) Aug 29 2010 That's a shame because a catch all is really needed. I hope the
- Stanislav Blinov (11/28) Aug 29 2010 Well, I'm not ready to file a bug report yet, but if you're desperate, I...
- Stanislav Blinov (2/34) Aug 29 2010 Well, yes, I am wrong, as typeof(T.length) is uint.
- Sean Kelly (2/15) Aug 30 2010 Yeah, sorry about that. This is fixed in SVN.
- Bob Cowdery (3/54) Aug 29 2010 Thank you. I was following the book blindly without thinking, and the
- Stanislav Blinov (5/59) Aug 29 2010 Well, there's no misguiding here. It's just that there are two versions
Hi I'm trying out some very simple concurrency tests to make sure I understand how it operates. However I'm having a few problems. I'm sure this is just lack of knowledge. I dont know enough to debug these things on my own yet. Bob The test below builds but does not output anything so I assume for some reason the pattern matching is not working. If I uncomment the line adding a variant pattern it gives me a compile error. Error: static assert "function with arguments (VariantN!(maxSize)) occludes successive function" But there is no successive function, its the last statement. Also I tried using a function address instead of a literal but that gives me a compile error: Error: static assert (false || false) is falseFrom the code it looks its saying that myfunc is not a function.import std.concurrency, std.stdio, std.variant; int main(char[][] args) { auto low = 0, high = 100; auto tid = spawn(&tfun); foreach(i;low .. high) { tid.send(thisTid,i); } writeln("Exiting"); return 0; } void myfunc(double x) { writeln("Got : ", x); } void tfun() { receive( //&myfunc, (int x) {writeln("Got : ", x);}//, //(Variant any) {writeln("Got : ", any);} ); };
Aug 29 2010
Bob Cowdery wrote:Hi I'm trying out some very simple concurrency tests to make sure I understand how it operates. However I'm having a few problems. I'm sure this is just lack of knowledge. I dont know enough to debug these things on my own yet. Bob The test below builds but does not output anything so I assume for some reason the pattern matching is not working. If I uncomment the line adding a variant pattern it gives me a compile error. Error: static assert "function with arguments (VariantN!(maxSize)) occludes successive function" But there is no successive function, its the last statement. Also I tried using a function address instead of a literal but that gives me a compile error: Error: static assert (false || false) is falseI'm not sure about Variant part yet (never tried it myself), but as for (int x) { /*...*/ } you've got the wrong signature. What you send is (Tid,int), but what you're trying to receive is (int). Try changing your tfun to receive (Tid, int x).From the code it looks its saying that myfunc is not a function.import std.concurrency, std.stdio, std.variant; int main(char[][] args) { auto low = 0, high = 100; auto tid = spawn(&tfun); foreach(i;low .. high) { tid.send(thisTid,i); } writeln("Exiting"); return 0; } void myfunc(double x) { writeln("Got : ", x); } void tfun() { receive( //&myfunc, (int x) {writeln("Got : ", x);}//, //(Variant any) {writeln("Got : ", any);} ); };
Aug 29 2010
Stanislav Blinov wrote:I'm not sure about Variant part yet (never tried it myself)Hmm, after some inspection I can say this is an implementation issue. You'll find that there are cases when what's told in TDPL doesn't work (see recent msg[0] or msg.field[0]? in this group, for example). I' for example, have just found that receive(OwnerTerminated) doesn't work as well. It's just that current dmd and phobos implementations need time to catch up TDPL (I know, things often go in reverse, but with D it's not the case :) )
Aug 29 2010
On 29/08/2010 20:17, Stanislav Blinov wrote:Stanislav Blinov wrote:That's a shame because a catch all is really needed. I hope the timeout works, not tried that yet. I will probably have explicit thread termination so if OwnerTerminated if a bit broken it's not so important to me but to be able to catch rogue messages and find out what they were is quite key.I'm not sure about Variant part yet (never tried it myself)Hmm, after some inspection I can say this is an implementation issue. You'll find that there are cases when what's told in TDPL doesn't work (see recent msg[0] or msg.field[0]? in this group, for example). I' for example, have just found that receive(OwnerTerminated) doesn't work as well. It's just that current dmd and phobos implementations need time to catch up TDPL (I know, things often go in reverse, but with D it's not the case :) )
Aug 29 2010
Bob Cowdery wrote:On 29/08/2010 20:17, Stanislav Blinov wrote:Well, I'm not ready to file a bug report yet, but if you're desperate, I *think* this may do the trick for you (assuming you use 2.048): in std/concurrency.d, line 382: Change if ( i < T.length ) to static if ( i < T.length-1 ) This works (for me, at least), even without recompilation of phobos. Mind you, I propose a hack made by hand, and Sean Kelly or other pros here may well find that I'm wrong, so it's at your own risk :)Stanislav Blinov wrote:That's a shame because a catch all is really needed. I hope the timeout works, not tried that yet. I will probably have explicit thread termination so if OwnerTerminated if a bit broken it's not so important to me but to be able to catch rogue messages and find out what they were is quite key.I'm not sure about Variant part yet (never tried it myself)Hmm, after some inspection I can say this is an implementation issue. You'll find that there are cases when what's told in TDPL doesn't work (see recent msg[0] or msg.field[0]? in this group, for example). I' for example, have just found that receive(OwnerTerminated) doesn't work as well. It's just that current dmd and phobos implementations need time to catch up TDPL (I know, things often go in reverse, but with D it's not the case :) )
Aug 29 2010
Stanislav Blinov wrote:Bob Cowdery wrote:Well, yes, I am wrong, as typeof(T.length) is uint.On 29/08/2010 20:17, Stanislav Blinov wrote:Well, I'm not ready to file a bug report yet, but if you're desperate, I *think* this may do the trick for you (assuming you use 2.048): in std/concurrency.d, line 382: Change if ( i < T.length ) to static if ( i < T.length-1 ) This works (for me, at least), even without recompilation of phobos. Mind you, I propose a hack made by hand, and Sean Kelly or other pros here may well find that I'm wrong, so it's at your own risk :)Stanislav Blinov wrote:That's a shame because a catch all is really needed. I hope the timeout works, not tried that yet. I will probably have explicit thread termination so if OwnerTerminated if a bit broken it's not so important to me but to be able to catch rogue messages and find out what they were is quite key.I'm not sure about Variant part yet (never tried it myself)Hmm, after some inspection I can say this is an implementation issue. You'll find that there are cases when what's told in TDPL doesn't work (see recent msg[0] or msg.field[0]? in this group, for example). I' for example, have just found that receive(OwnerTerminated) doesn't work as well. It's just that current dmd and phobos implementations need time to catch up TDPL (I know, things often go in reverse, but with D it's not the case :) )
Aug 29 2010
Stanislav Blinov Wrote:Stanislav Blinov wrote:Yeah, sorry about that. This is fixed in SVN.I'm not sure about Variant part yet (never tried it myself)Hmm, after some inspection I can say this is an implementation issue. You'll find that there are cases when what's told in TDPL doesn't work (see recent msg[0] or msg.field[0]? in this group, for example). I' for example, have just found that receive(OwnerTerminated) doesn't work as well. It's just that current dmd and phobos implementations need time to catch up TDPL (I know, things often go in reverse, but with D it's not the case :) )
Aug 30 2010
On 29/08/2010 19:17, Stanislav Blinov wrote:Bob Cowdery wrote:Thank you. I was following the book blindly without thinking, and the book says (int x) will match 'send(tid, 5)' etc.Hi I'm trying out some very simple concurrency tests to make sure I understand how it operates. However I'm having a few problems. I'm sure this is just lack of knowledge. I dont know enough to debug these things on my own yet. Bob The test below builds but does not output anything so I assume for some reason the pattern matching is not working. If I uncomment the line adding a variant pattern it gives me a compile error. Error: static assert "function with arguments (VariantN!(maxSize)) occludes successive function" But there is no successive function, its the last statement. Also I tried using a function address instead of a literal but that gives me a compile error: Error: static assert (false || false) is falseI'm not sure about Variant part yet (never tried it myself), but as for (int x) { /*...*/ } you've got the wrong signature. What you send is (Tid,int), but what you're trying to receive is (int). Try changing your tfun to receive (Tid, int x).From the code it looks its saying that myfunc is not a function.import std.concurrency, std.stdio, std.variant; int main(char[][] args) { auto low = 0, high = 100; auto tid = spawn(&tfun); foreach(i;low .. high) { tid.send(thisTid,i); } writeln("Exiting"); return 0; } void myfunc(double x) { writeln("Got : ", x); } void tfun() { receive( //&myfunc, (int x) {writeln("Got : ", x);}//, //(Variant any) {writeln("Got : ", any);} ); };
Aug 29 2010
Bob Cowdery wrote:On 29/08/2010 19:17, Stanislav Blinov wrote:Well, there's no misguiding here. It's just that there are two versions of send(), at least in current implementation. One is a free function that gets the destination Tid as its first parameter, the other is Tid's method. So send(tid, 5) is (almost) equivalent to tid.send(5).Bob Cowdery wrote:Thank you. I was following the book blindly without thinking, and the book says (int x) will match 'send(tid, 5)' etc.Hi I'm trying out some very simple concurrency tests to make sure I understand how it operates. However I'm having a few problems. I'm sure this is just lack of knowledge. I dont know enough to debug these things on my own yet. Bob The test below builds but does not output anything so I assume for some reason the pattern matching is not working. If I uncomment the line adding a variant pattern it gives me a compile error. Error: static assert "function with arguments (VariantN!(maxSize)) occludes successive function" But there is no successive function, its the last statement. Also I tried using a function address instead of a literal but that gives me a compile error: Error: static assert (false || false) is falseI'm not sure about Variant part yet (never tried it myself), but as for (int x) { /*...*/ } you've got the wrong signature. What you send is (Tid,int), but what you're trying to receive is (int). Try changing your tfun to receive (Tid, int x).From the code it looks its saying that myfunc is not a function.import std.concurrency, std.stdio, std.variant; int main(char[][] args) { auto low = 0, high = 100; auto tid = spawn(&tfun); foreach(i;low .. high) { tid.send(thisTid,i); } writeln("Exiting"); return 0; } void myfunc(double x) { writeln("Got : ", x); } void tfun() { receive( //&myfunc, (int x) {writeln("Got : ", x);}//, //(Variant any) {writeln("Got : ", any);} ); };
Aug 29 2010