Shared and race conditions

2017-11-29 Thread Wanderer via Digitalmars-d-learn
I'm trying to simulate a race condition in D with the following code: (https://run.dlang.io/is/RfOX0I) ``` import std.stdio; import core.thread; import std.concurrency; shared struct IdGen(T) { T id; this(T start) { id = start; } T next() { id = id.nex

Re: Shared and race conditions

2017-11-29 Thread Wanderer via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 16:19:05 UTC, Michael wrote: On Wednesday, 29 November 2017 at 16:13:13 UTC, Wanderer wrote: [...] I unfortunately cannot answer your question but I am noticing that running the code with DMD gives you an unordered sequence of IDs, but running with DMD-night

Re: Shared and race conditions

2017-11-29 Thread Wanderer via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 16:33:50 UTC, Steven Schveighoffer wrote: On 11/29/17 11:13 AM, Wanderer wrote: [...] [snip] [...] Using the compiler switch -vcg-ast, I see no synchronization of these methods. [...] That's what I assume, I was just lucky not to see a race. Thanks fo

Re: Shared and race conditions

2017-11-29 Thread Wanderer via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 17:03:42 UTC, Steven Schveighoffer wrote: On 11/29/17 11:13 AM, Wanderer wrote: I'm trying to simulate a race condition in D with the following code: (https://run.dlang.io/is/RfOX0I) One word of caution, I think the running of your code on run.dlang.io is c

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

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 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: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 10:10:41 UTC, maarten van damme via Digitalmars-d-learn wrote: an anyone explain me what I'm doing wrong here : [code] dstring[][dstring] providor_symbol_map; ... writeln(providor_symbol_map.keys.sort!((x,y)=>providor_symbol_map[x].length>=providor_symbol_map[y].len

Re: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
Sorry about typo, I meant providor_symbol_map.sort!((x,y)=>{x.value.length>y.value.length}) above.

Re: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
Aha, so you want to maintain "spam word" -> "set of senders" relationship, so it's actually "map of sets" and your declaration is correct. You only need to sort map's entries (key and value pairs together). If D supports that, it should be something like providor_symbol_map.sort!((x,y)=>{x.va

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-05-30 Thread Wanderer via Digitalmars-d-learn
I must note if the sequence is predictable, it's not random anymore, it's pseudo-random at most. Also, if anyone interested, PHP had such way to generate predictable sequences in the past, but after it was horribly misused by various people for crypto keys/password generation purposes, they h

Re: floating point conversion

2014-06-01 Thread Wanderer via Digitalmars-d-learn
The General rule is not to compare floats for equality, (is 0.0==-0.0, etc.). Use a epsilon based comparision scheme instead or a wrapper around it. That's not exactly true. You cannot (and should not) compare floating points for equality, and use epsilon-based comparison instead, only in one