Re: scope(exit) and Ctrl-C

2017-12-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 3 December 2017 at 02:56:38 UTC, H. S. Teoh wrote: Ha! I've been using Linux for decades now and this is the first time I'm aware of this function. Should simplify my code when I'm not planning to be Posix-portable. Thanks! In the same vein, make sure you read about timerfd and eve

Re: scope(exit) and Ctrl-C

2017-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 02, 2017 at 11:32:17AM +, Patrick Schluter via Digitalmars-d-learn wrote: > On Saturday, 2 December 2017 at 04:49:26 UTC, H. S. Teoh wrote: > > On Sat, Dec 02, 2017 at 04:38:29AM +, Adam D. Ruppe via > > Digitalmars-d-learn wrote: > > > [...] > > > > Signal handlers can potent

Re: scope(exit) and Ctrl-C

2017-12-02 Thread Patrick Schluter via Digitalmars-d-learn
On Saturday, 2 December 2017 at 04:49:26 UTC, H. S. Teoh wrote: On Sat, Dec 02, 2017 at 04:38:29AM +, Adam D. Ruppe via Digitalmars-d-learn wrote: [...] Signal handlers can potentially be invoked while inside a non-reentrant libc or OS function, so trying to do anything that (indirectly

Re: scope(exit) and Ctrl-C

2017-12-02 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-12-02 02:26, Adam D. Ruppe wrote: But this is intentional - there is no generic, reliable, cross-platform way of handling it natively. So you need to know the system and code it yourself. Not super hard but does take a bit of effort in your code. Since the "scope" block is not execute

Re: scope(exit) and Ctrl-C

2017-12-01 Thread codephantom via Digitalmars-d-learn
On Saturday, 2 December 2017 at 04:28:57 UTC, Wanderer wrote: Thanks! This works. But it seems a little bit suspicions that D's type for handler function has `nothrow` `@nogc` and `@system`. I wonder why is that? During execution of that handler, it make sense to prohibit the allocation of an

Re: scope(exit) and Ctrl-C

2017-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 02, 2017 at 04:38:29AM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Saturday, 2 December 2017 at 04:28:57 UTC, Wanderer wrote: > > Thanks! This works. But it seems a little bit suspicions that D's > > type for handler function has `nothrow` `@nogc` and `@system`. I > > wond

Re: scope(exit) and Ctrl-C

2017-12-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 2 December 2017 at 04:28:57 UTC, Wanderer wrote: Thanks! This works. But it seems a little bit suspicions that D's type for handler function has `nothrow` `@nogc` and `@system`. I wonder why is that? Signal handlers are ridiculously limited in what they are allowed to do. Really,

Re: scope(exit) and Ctrl-C

2017-12-01 Thread Wanderer via Digitalmars-d-learn
On Saturday, 2 December 2017 at 03:52:19 UTC, codephantom wrote: On Saturday, 2 December 2017 at 00:41:19 UTC, Wanderer wrote: Is there any method to cleanup on Ctrl-C? // -- import std.stdio; import core.thread; extern(C) void signal(int sig, void function(int

Re: scope(exit) and Ctrl-C

2017-12-01 Thread Wanderer via Digitalmars-d-learn
On Saturday, 2 December 2017 at 01:26:14 UTC, Adam D. Ruppe wrote: On Saturday, 2 December 2017 at 00:41:19 UTC, Wanderer wrote: I wonder why `scope(exit)` code is not executed when the program is terminated with Ctrl-C. It depends on what your operating system is. On win32, I believe it does

Re: scope(exit) and Ctrl-C

2017-12-01 Thread codephantom via Digitalmars-d-learn
On Saturday, 2 December 2017 at 00:41:19 UTC, Wanderer wrote: Is there any method to cleanup on Ctrl-C? // -- import std.stdio; import core.thread; extern(C) void signal(int sig, void function(int)); extern(C) void exit(int exit_val); extern(C) void handle(int

Re: scope(exit) and Ctrl-C

2017-12-01 Thread kdevel via Digitalmars-d-learn
On Saturday, 2 December 2017 at 00:41:19 UTC, Wanderer wrote: I wonder why `scope(exit)` code is not executed when the program is terminated with Ctrl-C. Which OS? For example: ``` import std.stdio; import core.thread; void main() { scope (exit) { writeln("Cleanup"); }

Re: scope(exit) and Ctrl-C

2017-12-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 2 December 2017 at 00:41:19 UTC, Wanderer wrote: I wonder why `scope(exit)` code is not executed when the program is terminated with Ctrl-C. It depends on what your operating system is. On win32, I believe it does run. On Linux (and I think Mac) you need to set a signal handler t

Re: scope(exit) and Ctrl-C

2017-12-01 Thread Ali Çehreli via Digitalmars-d-learn
On 12/01/2017 04:41 PM, Wanderer wrote: I wonder why `scope(exit)` code is not executed when the program is terminated with Ctrl-C. For example: ``` import std.stdio; import core.thread; void main() {     scope (exit)     {     writeln("Cleanup");     }     writeln("Waiting...");   

scope(exit) and Ctrl-C

2017-12-01 Thread Wanderer via Digitalmars-d-learn
I wonder why `scope(exit)` code is not executed when the program is terminated with Ctrl-C. For example: ``` import std.stdio; import core.thread; void main() { scope (exit) { writeln("Cleanup"); } writeln("Waiting..."); Thread.sleep(10.seconds); writeln("Done w