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

scope guard question

2020-06-29 Thread Arjan via Digitalmars-d-learn
``` void main() { import std.stdio; auto f = (){ string[] t; { // inner scope t ~= "hello"; scope( exit ) t ~= "world"; } // inner scope exit return t; }; f().writeln; // ["hello", "world"] } ``` removing the inner scope in f() gives ["hello"] So when no

Re: scope guard question

2020-06-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 June 2020 at 22:31:12 UTC, Arjan wrote: So when no inner scope is present, the scope exit 'runs' after the return? Is that indeed expected behavior according to the specification? Yes. A scope ends at the '}'. Destructors and scope guards execute then, after the return.

Re: scope guard question

2020-06-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/29/20 6:31 PM, Arjan wrote: ``` void main() {   import std.stdio;   auto f = (){     string[] t;     { // inner scope   t ~= "hello";   scope( exit ) t ~= "world";     } // inner scope exit     return t;   };   f().writeln; // ["hello", "world"] } ``` removing the inner

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 {

Linking D with C structs

2020-06-29 Thread Anthony via Digitalmars-d-learn
Hello, I'm trying to hand write some bindings to mongo-c-driver. (For learning purposes and to get the latest bindings). My binding code to convert to mongoc/mongoc.d is: = c interop file module mongoc/mongoc.d; import core.stdc.stdint; extern (c) { struct { uint domain;

Re: [DIP1000] Something I don't quite understand regarding 'scope'

2020-06-29 Thread ag0aep6g via Digitalmars-d-learn
On 29.06.20 02:28, Stanislav Blinov wrote: void local(Args...)(Args args) { } void main() @safe {     import std.stdio;     scope int* p;     local(p);   // Ok     writeln(p); // Error: scope variable p assigned to non-scope parameter _param_0 calling std.stdio.writeln!(int*).writeln }

Re: Linking D with C structs

2020-06-29 Thread kinke via Digitalmars-d-learn
On Monday, 29 June 2020 at 06:29:38 UTC, Anthony wrote: What does "__initZ" refer to? Does this refer to automatic initialization like "this()"? Almost, it's the static initializer for that struct, which is omitted because you apparently don't compile/link the module containing the struct

Waiting on file descriptor/socket *AND* thread messages

2020-06-29 Thread ichneumwn via Digitalmars-d-learn
Dear all, Is there some facility in D for a single statement/function call that will wait on both file descriptors, like Socket.select(), and will also wake up when there is something to be receive()'d? One solution would be to have my main thread use receive() and a helper thread that does

Re: [DIP1000] Something I don't quite understand regarding 'scope'

2020-06-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 June 2020 at 06:21:43 UTC, ag0aep6g wrote: Since `local` and `writeln` are templates, the attributes for their parameters are inferred from their bodies. `local!(int*)` doesn't do anything with the parameter, so it's inferred as `scope`. `writeln!(int*)` apparently does

Re: Waiting on file descriptor/socket *AND* thread messages

2020-06-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/29/20 5:14 AM, ichneumwn wrote: Dear all, Is there some facility in D for a single statement/function call that will wait on both file descriptors, like Socket.select(), and will also wake up when there is something to be receive()'d? Not in the standard library. Such things require an

Re: Waiting on file descriptor/socket *AND* thread messages

2020-06-29 Thread ichneumwn via Digitalmars-d-learn
On Monday, 29 June 2020 at 12:25:16 UTC, Steven Schveighoffer wrote: On 6/29/20 5:14 AM, ichneumwn wrote: [...] Not in the standard library. Such things require an event framework, because there is no OS-agnostic provided mechanism to sleep on all these things at once. I recommend looking

Re: Light-weight runtime

2020-06-29 Thread Kagamin via Digitalmars-d-learn
On Sunday, 28 June 2020 at 07:09:53 UTC, Виталий Фадеев wrote: I want light-weight runtime ! How to ? Runtime provides language features that rely on extra code. Removing that code from runtime means to give up on corresponding language features. This way you can implement only features you

Re: Calling C functions

2020-06-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/26/20 4:15 AM, Jacob Carlborg wrote: On Friday, 26 June 2020 at 00:30:22 UTC, Denis wrote: I have a two questions about calling C functions from D. (1) When passing a D callback to a C function, is there a way to write the code without having to prefix the callback declaration with

Re: Calling C functions

2020-06-29 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 29 June 2020 at 16:34:33 UTC, Steven Schveighoffer wrote: Are you sure? On the ABI page [1] , it says "The extern (C) and extern (D) calling convention matches the C calling convention used by the supported C compiler on the host system." In that case the documentation is wrong.

Re: Calling C functions

2020-06-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/29/20 1:50 PM, Jacob Carlborg wrote: On Monday, 29 June 2020 at 16:34:33 UTC, Steven Schveighoffer wrote: Are you sure? On the ABI page [1] , it says "The extern (C) and extern (D) calling convention matches the C calling convention used by the supported C compiler on the host system."