digitalmars.D.learn - std.concurrency msg passing
- Joshua Niehus (20/20) Oct 17 2012 Is the following snippet a bug?
- cal (7/27) Oct 18 2012 I can't see the bug? The receiver accepts a bool as an int, same
- Joshua Niehus (14/20) Oct 18 2012 I got myself into a situation where I dont know which will be
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (10/29) Oct 18 2012 I am not sure whether it is supposed to be, but the function must be a
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (2/2) Oct 18 2012 Sorry, wrong thread. :(
- Sean Kelly (4/19) Oct 18 2012 spawn() shouldn't allow you to spawn a delegate. Last I checked (which ...
- cal (3/11) Oct 18 2012 Why is foo a delegate here?
- Sean Kelly (4/13) Oct 18 2012 (which was admittedly a while ago), there were some compiler issues =
Is the following snippet a bug? --- import core.thread; import std.stdio, std.concurrency; void foo(Tid tid) { send(tid, true); } void main() { auto fooTid = spawn(&foo, thisTid); auto receiveInt = receiveTimeout(dur!"seconds"(10), (int isInt) { writeln("I should not be here"); }); } // output: "I should not be here" --- If not, is there some way I could achieve "receiveOnlyTimeout!(int)(dur, fun);" ? Thanks, Josh
Oct 17 2012
On Thursday, 18 October 2012 at 06:30:08 UTC, Joshua Niehus wrote:Is the following snippet a bug? --- import core.thread; import std.stdio, std.concurrency; void foo(Tid tid) { send(tid, true); } void main() { auto fooTid = spawn(&foo, thisTid); auto receiveInt = receiveTimeout(dur!"seconds"(10), (int isInt) { writeln("I should not be here"); }); } // output: "I should not be here" --- If not, is there some way I could achieve "receiveOnlyTimeout!(int)(dur, fun);" ? Thanks, JoshI can't see the bug? The receiver accepts a bool as an int, same way a normal function does. The timeout is long enough that foo gets a chance to send. If you want to stop the int receiver getting a bool, you could add another receiver with (bool) { // do nothing } or whatever before the (int) one, which will be a better match for the send.
Oct 18 2012
On Thursday, 18 October 2012 at 17:33:04 UTC, cal wrote:I got myself into a situation where I dont know which will be called first, the int or the bool and "when" the call happens matters. It was my assumption that "receiveTimeout(dur, (type){}); would distinguish between a bool and an int like it does for float and int. But I can see why it would treat true/false as 0/1, so not a bug. Anyway my current workaround is to define a few "Signal" structs and use those instead: struct SignalReady { blah } struct SignalXDone { blah } struct SignalYDone { blah } Thanks for the reply.I can't see the bug? The receiver accepts a bool as an int,same way a normal function does. The timeout is long enough that foo gets a chance to send. If you want to stop the int receiver getting a bool, you could add another receiver with (bool) { // do nothing } or whatever before the (int) one, which will be a better match for the send.
Oct 18 2012
On 10/17/2012 11:29 PM, Joshua Niehus wrote:Is the following snippet a bug? --- import core.thread; import std.stdio, std.concurrency; void foo(Tid tid) { send(tid, true); } void main() { auto fooTid = spawn(&foo, thisTid); auto receiveInt = receiveTimeout(dur!"seconds"(10), (int isInt) { writeln("I should not be here"); }); } // output: "I should not be here" --- If not, is there some way I could achieve "receiveOnlyTimeout!(int)(dur, fun);" ? Thanks, JoshI am not sure whether it is supposed to be, but the function must be a module-level function; so define it outside of main. When I did that, there was segmentation fault if I used thread priority. Workaround: 1) Take function out of main 2) Do not specify thread priority Created bug report: http://d.puremagic.com/issues/show_bug.cgi?id=8849 Ali
Oct 18 2012
On Oct 17, 2012, at 11:29 PM, Joshua Niehus <jm.niehus gmail.com> wrote:Is the following snippet a bug? =20 --- import core.thread; import std.stdio, std.concurrency; =20 void foo(Tid tid) { send(tid, true); } =20 void main() { auto fooTid =3D spawn(&foo, thisTid); auto receiveInt =3D receiveTimeout(dur!"seconds"(10), (int isInt) { writeln("I should not be here"); });spawn() shouldn't allow you to spawn a delegate. Last I checked (which = was admittedly a while ago), there were some compiler issues around = actually verifying the function signature sent to spawn() though.=
Oct 18 2012
On Thursday, 18 October 2012 at 18:31:09 UTC, Sean Kelly wrote:On Oct 17, 2012, at 11:29 PM, Joshua Niehus/* snip */void foo(Tid tid) { send(tid, true); }spawn() shouldn't allow you to spawn a delegate. Last I checked (which was admittedly a while ago), there were some compiler issues around actually verifying the function signature sent to spawn() though.Why is foo a delegate here?
Oct 18 2012
On Oct 18, 2012, at 11:35 AM, cal <callumenator gmail.com> wrote:On Thursday, 18 October 2012 at 18:31:09 UTC, Sean Kelly wrote:(which was admittedly a while ago), there were some compiler issues = around actually verifying the function signature sent to spawn() though.On Oct 17, 2012, at 11:29 PM, Joshua Niehus/* snip */void foo(Tid tid) { send(tid, true); }spawn() shouldn't allow you to spawn a delegate. Last I checked ==20 Why is foo a delegate here?My mistake. I misread the example.=
Oct 18 2012