Re: How to implement Canceleable spawn() from parent

2020-07-01 Thread Ali Çehreli via Digitalmars-d-learn
On 7/1/20 2:41 AM, aberba wrote: On Tuesday, 30 June 2020 at 14:43:40 UTC, Steven Schveighoffer wrote: On 6/30/20 10:15 AM, Simen Kjærås wrote: [...] My thinking is I don't want regular consumers using the package to think about the technicality of thread_joinAll() at all. Thinking about

Re: How to implement Canceleable spawn() from parent

2020-07-01 Thread aberba via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 14:43:40 UTC, Steven Schveighoffer wrote: On 6/30/20 10:15 AM, Simen Kjærås wrote: [...] My thinking is I don't want regular consumers using the package to think about the technicality of thread_joinAll() at all. Thinking about putting it in a mixin like: mixin

Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/20 10:15 AM, Simen Kjærås wrote: On Tuesday, 30 June 2020 at 13:44:38 UTC, aberba wrote: On Tuesday, 30 June 2020 at 12:48:32 UTC, Simen Kjærås wrote: On Tuesday, 30 June 2020 at 08:15:54 UTC, aberba wrote: On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote: On 6/29/20 4:34

Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 13:44:38 UTC, aberba wrote: On Tuesday, 30 June 2020 at 12:48:32 UTC, Simen Kjærås wrote: On Tuesday, 30 June 2020 at 08:15:54 UTC, aberba wrote: On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote: On 6/29/20 4:34 PM, aberba wrote: > So with this, without

Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/20 9:44 AM, aberba wrote: On Tuesday, 30 June 2020 at 12:48:32 UTC, Simen Kjærås wrote: So I guess the error is elsewhere, but I'm not sure where and how. Yeah, you're right. I changed receiveTimeout() to receive() to try something and forgot to change it back. Jeez, I hate

Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread aberba via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 12:48:32 UTC, Simen Kjærås wrote: On Tuesday, 30 June 2020 at 08:15:54 UTC, aberba wrote: On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote: On 6/29/20 4:34 PM, aberba wrote: > So with this, without the Thread.sleep() to block main from exiting, the >

Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 08:15:54 UTC, aberba wrote: On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote: On 6/29/20 4:34 PM, aberba wrote: > So with this, without the Thread.sleep() to block main from exiting, the > spawned thread will terminate immediately. You can call

Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread aberba via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote: On 6/29/20 4:34 PM, aberba wrote: > So with this, without the Thread.sleep() to block main from exiting, the > spawned thread will terminate immediately. You can call core.thread.thread_joinAll at the end of main. So I tried that

Re: How to implement Canceleable spawn() from parent

2020-06-29 Thread Ali Çehreli via Digitalmars-d-learn
On 6/29/20 4:34 PM, aberba wrote: > So with this, without the Thread.sleep() to block main from exiting, the > spawned thread will terminate immediately. You can call core.thread.thread_joinAll at the end of main. Another way would be to wait for a worker's exit by looking for LinkTerminated

Re: How to implement Canceleable spawn() from parent

2020-06-29 Thread aberba via Digitalmars-d-learn
On Sunday, 28 June 2020 at 14:23:01 UTC, Stanislav Blinov wrote: On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote: [...] The error you're getting is because you're passing a pointer to a delegate instead of a delegate. [...] So with this, without the Thread.sleep() to block

Re: How to implement Canceleable spawn() from parent

2020-06-29 Thread Johann Lermer via Digitalmars-d-learn
I'm doing this in an X11 application in order to send a timer event every 100 milliseconds to the main event queue. class Application { shared private bool s_tick; void clock_task (shared X11.Display* disp, X11.Atom atom, X11.Window win) { for (;;) { try {

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread Ali Çehreli via Digitalmars-d-learn
On 6/28/20 4:08 PM, aberba wrote: So I checked receiveTimeout() when I was looking for what I could use. I wish there was an example in the docs. https://dlang.org/library/std/concurrency/receive_timeout.html I have an example of it:

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn
On Sunday, 28 June 2020 at 23:39:07 UTC, Stanislav Blinov wrote: On Sunday, 28 June 2020 at 23:02:26 UTC, aberba wrote: I believe this: StopWatch sw; sw.start; works becuse D structs are initialized by default, right? I've never actually done it this way. Little details. Yup. You can also

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 28 June 2020 at 23:02:26 UTC, aberba wrote: I believe this: StopWatch sw; sw.start; works becuse D structs are initialized by default, right? I've never actually done it this way. Little details. Yup. You can also do a auto sw = StopWatch(AutoStart.yes); and not have to call

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn
On Sunday, 28 June 2020 at 23:02:26 UTC, aberba wrote: On Sunday, 28 June 2020 at 14:23:01 UTC, Stanislav Blinov wrote: On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote: Thanks. I believe this: StopWatch sw; sw.start; works becuse D structs are initialized by default, right? I've

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn
On Sunday, 28 June 2020 at 14:23:01 UTC, Stanislav Blinov wrote: On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote: Thanks. I believe this: StopWatch sw; sw.start; works becuse D structs are initialized by default, right? I've never actually done it this way. Little details.

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote: Getting error: Error: template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(Tid id) @system, Tid), candidates are: /usr/include/dmd/phobos/std/concurrency.d(460,5): spawn(F, T...)(F fn, T

How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn
Trying to implement a setInterval() that I can cancel using: Tid tid = setInterval(2000, (){ writeln("hello");}) And then I can do: stopInterval(tid); With something like this: stopInterval(Tid tid) { send(tid, "cancel"); } import std.stdio : writeln; import std.concurrency : receive,