segfault when using std.parallelism and std.process.executeShell

Nikhil Padmanabhan nikhil.padmanabhan at gmail.com
Thu Dec 12 20:33:01 PST 2013


Hi,

The following code dies with a segfault :

import std.stdio, std.parallelism, std.process;

void main() {
	auto a=["hello","world","goodbye"];
	foreach(s; parallel(a,1)) {
		auto ls=executeShell("echo "~s);
		writeln(ls.output);
	}
}

both in ldc and dmd. Removing either the "parallel" or running 
something other than executeShell (eg. just doing a writeln) 
works, which suggests to me that it's something about the way 
executeShell is interacting with parallel.

Pulling it up in lldb, I get :
* thread #2: tid = 0x16738e6, 0x0000000100039198 
test`D3std7process7environFNbNdNeZxPPa + 20, stop reason = 
EXC_BAD_ACCESS (code=1, address=0x0)
     frame #0: 0x0000000100039198 
test`D3std7process7environFNbNdNeZxPPa + 20

Any thoughts on what might be going wrong? Is executeShell 
somehow not threadsafe?

Thanks!
-- Nikhil


More information about the Digitalmars-d-learn mailing list