Re: Can't get Visual D to come up. No warnings, no errors, no nothing

2014-09-22 Thread evilrat via Digitalmars-d-learn

On Tuesday, 23 September 2014 at 05:13:58 UTC, evilrat wrote:
On Tuesday, 23 September 2014 at 03:14:27 UTC, WhatMeWorry 
wrote:
I've downloaded the "isolated shell and the integrated 
package" installer and successfully installed them both. But 
after that I have no clue as to how to proceed. I only ran 
vdserver.exe because it is the only executable that I can find.


shell version have name like "Visual Studio 2013"


and finally, located at  Program Files/Microsoft Visual Studio 
12.0/Common7/IDE/devenv.exe


Re: Can't get Visual D to come up. No warnings, no errors, no nothing

2014-09-22 Thread evilrat via Digitalmars-d-learn

On Tuesday, 23 September 2014 at 03:14:27 UTC, WhatMeWorry wrote:
On Monday, 22 September 2014 at 03:30:22 UTC, Vladimir 
Panteleev wrote:
On Monday, 22 September 2014 at 03:21:44 UTC, WhatMeWorry 
wrote:

Anybody installed Visual D recently?

As per the install instructions, I downloaded the  Visual 
Studio isolated Shell 2013 and its integrated package. 
Everything went smoothly.  I then downloaded Visual D and 
installed it with no problems. However, when I try to run the 
vdserver.exe application, nothing happens?


Am I missing something obvious?


Why are you running vdserver.exe?

Since Visual D is a VS extension, wouldn't the expected way to 
use it is to start Visual Studio [Shell], and create a D 
project?


Right. Then I guess I should be asking how does one start the 
Visual Studio Shell (isolated or otherwise)?


I've downloaded the "isolated shell and the integrated package" 
installer and successfully installed them both. But after that 
I have no clue as to how to proceed. I only ran vdserver.exe 
because it is the only executable that I can find.


shell version have name like "Visual Studio 2013"


Re: Does remove immutability using cast to pass in a function make sense?

2014-09-22 Thread Ali Çehreli via Digitalmars-d-learn

On 09/22/2014 07:07 PM, AsmMan wrote:

I have this array:

static immutable string[] months = ["jan", "fev", ...];

I need to pass it into canFind(). But it doesn't works with immutables
so I need to cast it like in canFind(cast(string[]) months, month) to
work. There's a reason related to design why it doesn't work with
immutables or a function just wasn't written?

What I want to know is if I'm doing something wrong in casting it to
work. I know from C which such casts should be done carefully


What is the compiler version? The following works with dmd git head:

import std.algorithm;

static immutable string[] months = ["jan", "fev" ];

void main()
{
assert(months.canFind("jan"));
}

If it still doesn't work for you please show us a minimal program that 
demonstrates the problem.


Ali



Re: Can't get Visual D to come up. No warnings, no errors, no nothing

2014-09-22 Thread WhatMeWorry via Digitalmars-d-learn
On Monday, 22 September 2014 at 03:30:22 UTC, Vladimir Panteleev 
wrote:

On Monday, 22 September 2014 at 03:21:44 UTC, WhatMeWorry wrote:

Anybody installed Visual D recently?

As per the install instructions, I downloaded the  Visual 
Studio isolated Shell 2013 and its integrated package. 
Everything went smoothly.  I then downloaded Visual D and 
installed it with no problems. However, when I try to run the 
vdserver.exe application, nothing happens?


Am I missing something obvious?


Why are you running vdserver.exe?

Since Visual D is a VS extension, wouldn't the expected way to 
use it is to start Visual Studio [Shell], and create a D 
project?


Right. Then I guess I should be asking how does one start the 
Visual Studio Shell (isolated or otherwise)?


I've downloaded the "isolated shell and the integrated package" 
installer and successfully installed them both. But after that I 
have no clue as to how to proceed. I only ran vdserver.exe 
because it is the only executable that I can find.




Does remove immutability using cast to pass in a function make sense?

2014-09-22 Thread AsmMan via Digitalmars-d-learn

I have this array:

static immutable string[] months = ["jan", "fev", ...];

I need to pass it into canFind(). But it doesn't works with 
immutables so I need to cast it like in canFind(cast(string[]) 
months, month) to work. There's a reason related to design why it 
doesn't work with immutables or a function just wasn't written?


What I want to know is if I'm doing something wrong in casting it 
to work. I know from C which such casts should be done carefully


Re: can't understand why code do not working

2014-09-22 Thread Ali Çehreli via Digitalmars-d-learn

On 09/22/2014 01:12 PM, Suliman wrote:

> std.concurrency.OwnerTerminated@std\concurrency.d(234): Owner terminated
> 

I feel bad about that uninteresting first example that lost you time. :(

There are a number of options:

- The main thread can call thread_joinAll() to wait for all workers to 
finish.


- The threads can have a protocol to signal each other that they are 
done. (I used 'struct Exit' in that chapter.)


- Threads can detect exceptions like OwnerTerminated and act accordingly.

The rest of the chapter has examples of those options.

Ali



Re: can't understand why code do not working

2014-09-22 Thread Cliff via Digitalmars-d-learn

On Monday, 22 September 2014 at 21:28:25 UTC, Cliff wrote:
On Monday, 22 September 2014 at 21:24:58 UTC, monarch_dodra 
wrote:
On Monday, 22 September 2014 at 21:19:37 UTC, Steven 
Schveighoffer wrote:

On 9/22/14 4:37 PM, Cliff wrote:



Is stdout threadsafe?


Yes, stdout is thread safe, it's based on C's stdout which is 
thread safe.


-Steve


Techinallly, though thread "safe", concurrent writes will 
create garbled text. D goes one step further in the sense that 
it prevents concurrent writes entirely.


The reason I ask is that the first iteration of his loop does 
not show up in stdout as presented.  I would expect 1 and 3 to 
be the first two lines of the output.


For that matter I also don't expect the 6 and 18 - nevermind, 
there must be something else going on with that loop.  He must 
have changed the loop limits.


Re: can't understand why code do not working

2014-09-22 Thread Cliff via Digitalmars-d-learn

On Monday, 22 September 2014 at 21:24:58 UTC, monarch_dodra wrote:
On Monday, 22 September 2014 at 21:19:37 UTC, Steven 
Schveighoffer wrote:

On 9/22/14 4:37 PM, Cliff wrote:



Is stdout threadsafe?


Yes, stdout is thread safe, it's based on C's stdout which is 
thread safe.


-Steve


Techinallly, though thread "safe", concurrent writes will 
create garbled text. D goes one step further in the sense that 
it prevents concurrent writes entirely.


The reason I ask is that the first iteration of his loop does not 
show up in stdout as presented.  I would expect 1 and 3 to be the 
first two lines of the output.


Re: can't understand why code do not working

2014-09-22 Thread monarch_dodra via Digitalmars-d-learn

On Monday, 22 September 2014 at 20:12:28 UTC, Suliman wrote:
std.concurrency.OwnerTerminated@std\concurrency.d(234): Owner 
terminated


You need to make sure your main waits for its workers before 
exiting. When main "dies", it sends an exception message to 
anyone still working.


Re: can't understand why code do not working

2014-09-22 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 22 September 2014 at 21:19:37 UTC, Steven 
Schveighoffer wrote:

On 9/22/14 4:37 PM, Cliff wrote:



Is stdout threadsafe?


Yes, stdout is thread safe, it's based on C's stdout which is 
thread safe.


-Steve


Techinallly, though thread "safe", concurrent writes will create 
garbled text. D goes one step further in the sense that it 
prevents concurrent writes entirely.


Re: can't understand why code do not working

2014-09-22 Thread monarch_dodra via Digitalmars-d-learn

On Monday, 22 September 2014 at 20:37:42 UTC, Cliff wrote:

Is stdout threadsafe?


Yes. All io operations lock in D, so are thread safe. You will 
never have interlaced io. If you want to do several opeations, 
then you can use LockingTextWriter, which is faster, s it locks 
once until you are finished. Though to be honest, the io itself 
is slow enough that I've never needed it.


Re: can't understand why code do not working

2014-09-22 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/22/14 4:37 PM, Cliff wrote:



Is stdout threadsafe?


Yes, stdout is thread safe, it's based on C's stdout which is thread safe.

-Steve


New changes to DDOC where is the tag coming from in parent classes?

2014-09-22 Thread Gary Willoughby via Digitalmars-d-learn
Below is a change that results from re-generating my 
documentation using ddoc. I wonder where the new  tags are 
coming from that wrap the parent class name.


-class class="symbol">Button: tkd.widget.textwidget.TextWidget;
+class class="symbol">Button: 
tkd.widget.textwidget.TextWidget;


Has there been a new ddoc symbol defined and not mentioned in: 
http://dlang.org/ddoc.html I've redefined most of these in my own 
.ddoc file and can't seem to get rid of the new tag. Is there a 
master ddoc file being read from somewhere?


Any help?


Re: can't understand why code do not working

2014-09-22 Thread Cliff via Digitalmars-d-learn

On Monday, 22 September 2014 at 20:12:28 UTC, Suliman wrote:

void worker()
{
int value = 0;
while (value <=10)
{

value = receiveOnly!int();
writeln(value);
int result = value * 3;
ownerTid.send(result);
}
}

give me:

Running .\app1.exe
2
6
3
9
4
12
5
15
6
18
std.concurrency.OwnerTerminated@std\concurrency.d(234): Owner 
terminated


0x00405777 in pure @safe void 
std.concurrency.receiveOnly!(int).receiveOnly().__
lambda3(std.concurrency.OwnerTerminated) at 
C:\DMD\dmd2\windows\bin\..\..\src\ph

obos\std\concurrency.d(730)
0x0040B88D in @safe void std.concurrency.Message.map!(pure 
@safe void function(s
td.concurrency.OwnerTerminated)*).map(pure @safe void 
function(std.concurrency.O
wnerTerminated)*) at 
C:\DMD\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(

158)
0x0040B0B6 in 
D3std11concurrency10MessageBox151__T3getTDFNbNfiZvTPFNaNfC3std11co
ncurrency14LinkTerminatedZvTP8047E12172B30CAF110369CD57C78A37 
at C:\DMD\dmd2\win

dows\bin\..\..\src\phobos\std\concurrency.d(1159)


Is stdout threadsafe?


Re: can't understand why code do not working

2014-09-22 Thread Suliman via Digitalmars-d-learn

void worker()
{
int value = 0;
while (value <=10)
{

value = receiveOnly!int();
writeln(value);
int result = value * 3;
ownerTid.send(result);
}
}

give me:

Running .\app1.exe
2
6
3
9
4
12
5
15
6
18
std.concurrency.OwnerTerminated@std\concurrency.d(234): Owner 
terminated


0x00405777 in pure @safe void 
std.concurrency.receiveOnly!(int).receiveOnly().__
lambda3(std.concurrency.OwnerTerminated) at 
C:\DMD\dmd2\windows\bin\..\..\src\ph

obos\std\concurrency.d(730)
0x0040B88D in @safe void std.concurrency.Message.map!(pure @safe 
void function(s
td.concurrency.OwnerTerminated)*).map(pure @safe void 
function(std.concurrency.O
wnerTerminated)*) at 
C:\DMD\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(

158)
0x0040B0B6 in 
D3std11concurrency10MessageBox151__T3getTDFNbNfiZvTPFNaNfC3std11co
ncurrency14LinkTerminatedZvTP8047E12172B30CAF110369CD57C78A37 at 
C:\DMD\dmd2\win

dows\bin\..\..\src\phobos\std\concurrency.d(1159)



Re: can't understand why code do not working

2014-09-22 Thread Ali Çehreli via Digitalmars-d-learn

On 09/22/2014 12:36 PM, Suliman wrote:


void worker()
{
 int value = 0;
 value = receiveOnly!int();
 writeln(value);
 int result = value * 3;
 ownerTid.send(result);
}


Your worker terminates after receiving one int and sending one response. 
It should be waiting in a loop.


Ali



can't understand why code do not working

2014-09-22 Thread Suliman via Digitalmars-d-learn
Already 1 hour I am looking at example from 
http://ddili.org/ders/d.en/concurrency.html and my modification 
of it, and can't understand what's difference? Why it's output 
only:

1
3

and then do not do nothing!

import std.stdio;
import std.concurrency;
import core.thread;


void main()
{
   Tid wk = spawn(&worker);
   foreach(v; 1..5)
   {
wk.send(v);
int result = receiveOnly!int();
writeln(result);
   }
}

void worker()
{
int value = 0;
value = receiveOnly!int();
writeln(value);
int result = value * 3;
ownerTid.send(result);
}


Re: Segfault in DMD OSX

2014-09-22 Thread Etienne via Digitalmars-d-learn

Here's with debug symbols in DMD

Program received signal SIGSEGV, Segmentation fault.
0x00010013c4d0 in TemplateInstance::findBestMatch (this=0x101c34050, 
sc=0x12058d740, fargs=0x0) at template.c:7329
7329 tempdecl->kind(), tempdecl->parent->toPrettyChars(), 
tempdecl->ident->toChars());

(gdb) print havetempdecl
$1 = false
(gdb) print tempdecl->kind()
$2 = 0x100290149 "overload alias"
(gdb) print tempdecl->parent->toPrettyChars()
Cannot access memory at address 0x0
(gdb) print tempdecl->ident->toChars()
$3 = 0x100515bd8 "Array"
(gdb) print tempdel->parent
No symbol "tempdel" in current context.
(gdb) print tempdecl->parent
$4 = (Dsymbol *) 0x0
(gdb) print tempdecl
$5 = (Dsymbol *) 0x1095fbc50
(gdb)

The tempdecl->parent is being accessed even though it may be null in :7329 :
  ::error(loc, "%s %s.%s does not match any template declaration",
tempdecl->kind(), tempdecl->parent->toPrettyChars(), 
tempdecl->ident->toChars());




Re: Segfault in DMD OSX

2014-09-22 Thread Etienne via Digitalmars-d-learn

I managed to get gdb running, here's what I get:

Starting program: /bin/dmd -lib -m64 -g source/event/internals/epoll.d 
source/event/internals/kqueue.d source/event/internals/path.d 
source/event/internals/validator.d source/event/internals/hashmap.d 
source/event/internals/memory.d source/event/internals/socket_compat.d 
source/event/internals/win32.d source/event/file.d source/event/tcp.d 
source/event/timer.d source/event/watcher.d source/event/dns.d 
source/event/types.d source/event/windows.d source/event/events.d 
source/event/notifier.d source/event/signal.d source/event/threads.d 
source/event/udp.d source/event/d.d source/event/posix2.d 
source/event/posix.d source/event/test.d

Using FreeBSD KQueue for events

Program received signal SIGSEGV, Segmentation fault.
0x0001000d818b in TemplateInstance::findBestMatch(Scope*, 
Array*) ()

(gdb) show registers
Undefined show command: "registers". Try "help show".
(gdb) registers
Undefined command: "registers". Try "help".
(gdb) info registers
rax 0x1093fb750 4450137936
rbx 0x0 0
rcx 0x0 0
rdx 0x7fff5fbfebf0 140734799801328
rsi 0x12048d950 4836612432
rdi 0x0 0
rbp 0x7fff5fbfed60 0x7fff5fbfed60
rsp 0x7fff5fbfecb0 0x7fff5fbfecb0
r8 0x106117660 4396775008
r9 0x7fff5fbfed00 140734799801600
r10 0x7fff5fbfed00 140734799801600
r11 0x1a340b60 439618400
r12 0x0 0
r13 0x1001b14cf 4296742095
r14 0x0 0
r15 0x101a34050 4322443344
rip 0x1000d818b 0x1000d818b Array*)+1339>

eflags 0x10246 [ PF ZF IF RF ]
cs 0x2b 43
ss 
ds 
es 
fs 0x0 0
gs 0x93f 155123712
(gdb)

On 2014-09-22 12:35 PM, Etienne wrote:

I'm having issues with DMD returning exit code -11 rather than compiling
my project. I have no idea how to debug this, I'm using Mac OS X 10.9.4
with latest git DMD tagged 2.066, and this project:

https://github.com/etcimon/event.d

When I hit `dub run`, I get the exit code. Not sure why or where the
problem comes from, I can't get GDB to run on the mac (something about
Mach task port error in gdb), and dmd DEBUG gives no additional info.
Any ideas?




Segfault in DMD OSX

2014-09-22 Thread Etienne via Digitalmars-d-learn
I'm having issues with DMD returning exit code -11 rather than compiling 
my project. I have no idea how to debug this, I'm using Mac OS X 10.9.4 
with latest git DMD tagged 2.066, and this project:


https://github.com/etcimon/event.d

When I hit `dub run`, I get the exit code. Not sure why or where the 
problem comes from, I can't get GDB to run on the mac (something about 
Mach task port error in gdb), and dmd DEBUG gives no additional info. 
Any ideas?


Re: Cannot deduce from type

2014-09-22 Thread Chris via Digitalmars-d-learn

On Monday, 22 September 2014 at 15:00:09 UTC, anonymous wrote:

On Monday, 22 September 2014 at 14:45:31 UTC, Chris wrote:

Why is that?

import std.stdio, std.array

void main() {
 auto output = appender!(string);
 output ~= "world!";
//  output.data.insertInPlace(0, "Hello, ");  // Doesn't work
 auto asString = output.data;
 asString.insertInPlace(0, "Hello, ");  // Works
 writeln(asString);  // prints "Hello, world!"
}

Error: template std.array.insertInPlace cannot deduce function 
from argument types !()(string, int, string), candidates are:

.dvm/compilers/dmd-2.066.0/linux/bin/../../src/phobos/std/array.d(1031):
  std.array.insertInPlace(T, U...)(ref T[] array, size_t 
pos, U stuff) if (!isSomeString!(T[]) && 
allSatisfy!(isInputRangeOrConvertible!T, U) && U.length > 0)

.dvm/compilers/dmd-2.066.0/linux/bin/../../src/phobos/std/array.d(1097):
  std.array.insertInPlace(T, U...)(ref T[] array, size_t 
pos, U stuff) if (isSomeString!(T[]) && 
allSatisfy!(isCharOrStringOrDcharRange, U))


output.data is a method returning a string. That is, the 
returned

string is not an lvalue, it doesn't have an address, it cannot
be passed in a ref parameter. But insertInPlace's first 
parameter

is ref. So, no can do.


I see. Thanks.


Also note that `writeln(output.data);` prints "world!" without
"Hello, ".


Because I only append "world!" to it. You would have to print the
variable "asString" to get "Hello, world!"


Re: Cannot deduce from type

2014-09-22 Thread anonymous via Digitalmars-d-learn

On Monday, 22 September 2014 at 14:45:31 UTC, Chris wrote:

Why is that?

import std.stdio, std.array

void main() {
  auto output = appender!(string);
  output ~= "world!";
//  output.data.insertInPlace(0, "Hello, ");  // Doesn't work
  auto asString = output.data;
  asString.insertInPlace(0, "Hello, ");  // Works
  writeln(asString);  // prints "Hello, world!"
}

Error: template std.array.insertInPlace cannot deduce function 
from argument types !()(string, int, string), candidates are:

.dvm/compilers/dmd-2.066.0/linux/bin/../../src/phobos/std/array.d(1031):
   std.array.insertInPlace(T, U...)(ref T[] array, size_t 
pos, U stuff) if (!isSomeString!(T[]) && 
allSatisfy!(isInputRangeOrConvertible!T, U) && U.length > 0)

.dvm/compilers/dmd-2.066.0/linux/bin/../../src/phobos/std/array.d(1097):
   std.array.insertInPlace(T, U...)(ref T[] array, size_t 
pos, U stuff) if (isSomeString!(T[]) && 
allSatisfy!(isCharOrStringOrDcharRange, U))


output.data is a method returning a string. That is, the returned
string is not an lvalue, it doesn't have an address, it cannot
be passed in a ref parameter. But insertInPlace's first parameter
is ref. So, no can do.

Also note that `writeln(output.data);` prints "world!" without
"Hello, ".


Cannot deduce from type

2014-09-22 Thread Chris via Digitalmars-d-learn

Why is that?

import std.stdio, std.array

void main() {
  auto output = appender!(string);
  output ~= "world!";
//  output.data.insertInPlace(0, "Hello, ");  // Doesn't work
  auto asString = output.data;
  asString.insertInPlace(0, "Hello, ");  // Works
  writeln(asString);  // prints "Hello, world!"
}

Error: template std.array.insertInPlace cannot deduce function 
from argument types !()(string, int, string), candidates are:
.dvm/compilers/dmd-2.066.0/linux/bin/../../src/phobos/std/array.d(1031): 
   std.array.insertInPlace(T, U...)(ref T[] array, size_t 
pos, U stuff) if (!isSomeString!(T[]) && 
allSatisfy!(isInputRangeOrConvertible!T, U) && U.length > 0)
.dvm/compilers/dmd-2.066.0/linux/bin/../../src/phobos/std/array.d(1097): 
   std.array.insertInPlace(T, U...)(ref T[] array, size_t 
pos, U stuff) if (isSomeString!(T[]) && 
allSatisfy!(isCharOrStringOrDcharRange, U))


Re: parallel foreach hangs

2014-09-22 Thread anonymous via Digitalmars-d-learn

On Monday, 22 September 2014 at 11:25:53 UTC, Daniel Kozak wrote:

this code never end

import std.stdio;
import std.file;
import std.parallelism : parallel;
import std.algorithm : filter;

void main(string[] args)
{
foreach(d; parallel(args[1 .. $], 1))
{
auto phpFiles = 
filter!`endsWith(a.name,".php")`(dirEntries(d,SpanMode.depth));

writeln(phpFiles);
}
}


Works for me.

Be aware that dirEntries traverses the whole directory structure
recursively. So when you let it loose on something like root or
your home directory, it may take a while.

If that's not it, try to define a complete test scenario:
directories, files, compiler version, command line for compiling,
command line for running, etc.


Re: how to create and compile reesources for dmd 64

2014-09-22 Thread Kagamin via Digitalmars-d-learn
You probably compile resource to compiled resource format. If you 
compile it to coff, linker should accept it.


Re: How does GC.addRange work?

2014-09-22 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/21/14 3:00 PM, Gary Willoughby wrote:

On Saturday, 20 September 2014 at 23:08:08 UTC, ketmar via
Digitalmars-d-learn wrote:

On Sat, 20 Sep 2014 22:21:13 +
Gary Willoughby via Digitalmars-d-learn
 wrote:


So zeroing values will inform the GC the reference has gone?

yes.


Thanks, i just wanted to make it clear in my mind.


Just to be crystal clear, zeroing values in that range will make the GC 
able to collect the memory that those values previously pointed at. 
However, you have to remove the range in order for the GC to ignore that 
data. In other words, if you zero that memory, the GC will continue to 
scan those zeros until you GC.removeRange it.


-Steve


parallel foreach hangs

2014-09-22 Thread Daniel Kozak via Digitalmars-d-learn

this code never end

import std.stdio;
import std.file;
import std.parallelism : parallel;
import std.algorithm : filter;

void main(string[] args)
{
foreach(d; parallel(args[1 .. $], 1))
{
auto phpFiles = 
filter!`endsWith(a.name,".php")`(dirEntries(d,SpanMode.depth));

writeln(phpFiles);
}
}


Re: put string[] into a appender without loop?

2014-09-22 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 21 September 2014 at 23:50:50 UTC, H. S. Teoh via 
Digitalmars-d-learn wrote:
On Sun, Sep 21, 2014 at 11:41:56PM +, AsmMan via 
Digitalmars-d-learn wrote:
I'd like to copy an array string into a appender!string() but 
I can't
see how to do this without loop myself over the string array. 
Is there

a native function or should I write it myself?


Try this:

import std.array : appender;
import std.algorithm : joiner, copy;

string[] arr = ["ab", "cd", "efg"];
auto app = appender!string();
arr.joiner.copy(app);
assert(app.data == "abcdefg");


T


FYI, that's probably scary expensive in terms of 
encoding/decoding.


Using the "free" std.range.put should take care of everything, 
natively.


Re: Why is amap implemented as a member function of TaskPool?

2014-09-22 Thread Atila Neves via Digitalmars-d-learn

On Saturday, 20 September 2014 at 06:46:43 UTC, Nordlöw wrote:
On Thursday, 18 September 2014 at 19:49:00 UTC, Atila Neves 
wrote:
I had to roll my own parallel map today, but at least I did 
get a nice 3x speedup.


Is your own parallel map public somewhere? It would be 
interesting to see it.


I just did the simplest, stupidest thing that would work, so it's 
probably buggy. It works where I used it (and was faster) so 
that's all I needed to know. To even think of releasing this I'd 
use atomics instead of the mutex and try to break it in all sorts 
of ways. But here it is anyway:


private auto pmap(alias fun, R)(R range) if(isInputRange!R) {
import std.parallelism;
import core.sync.mutex;

static __gshared Mutex mutex;
if(mutex is null) mutex = new Mutex;
typeof(fun(range.front))[] values;
foreach(i, value; range.parallel) {
auto newValue = fun(value);
synchronized(mutex) {
if(values.length < i + 1) values.length = i + 1;
values[i] = newValue;
}
}

return values;
}

Oh, and the reason I don't just append to `values` is that I need 
to preserve the original order.


Atila


Re: Why is amap implemented as a member function of TaskPool?

2014-09-22 Thread Atila Neves via Digitalmars-d-learn
On Saturday, 20 September 2014 at 07:25:45 UTC, Russel Winder via 
Digitalmars-d-learn wrote:
On Sat, 2014-09-20 at 06:46 +, "Nordlöw" via 
Digitalmars-d-learn

wrote:
On Thursday, 18 September 2014 at 19:49:00 UTC, Atila Neves 
wrote:
> I had to roll my own parallel map today, but at least I did 
> get a nice 3x speedup.


How many cores? Is the problem a data parallel one and hence 
should show

linear speedup?


It depends on the data. I was running analysis on a build 
dependency graph. It'd depend on the dependency tree topology. I 
have 4 cores with hyperthreading. 3x speedup seems good to me, 
especially since the implementation is recursive.




Is your own parallel map public somewhere? It would be 
interesting to see it.


Particularly if it can be used to improved the code in 
std.parallelism.


Now that I looked at the bug id referenced above, I don't think 
it'd help. I can see all sorts of problems with guaranteeing no 
mutable references are captured by the delegate.


Atila