Using Parallel prints duplicates nor misses.

Vino.B vino.bheeman at hotmail.com
Sun Sep 17 07:47:22 UTC 2017


Hi,

  Request your help, the below code sometime prints duplicate and 
some time miss the entry. due to which any code written below the 
line "foreach (d; parallel(dFiles[], 1))" are some time 
duplicated and some time not executed(skips). tired adding sort 
and uniq to the writeln but no luck.


Code:
import std.algorithm: filter, map, sort, uniq;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: writeln;
import std.parallelism: parallel;

void main () {
   	auto SizeDirlst = Array!string ("C:\\Temp\\TEAM\\BACKUP", 
"C:\\Temp\\TEAM\\EXPORT");
	foreach (FFs; SizeDirlst[]) {
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));
	foreach (d; parallel(dFiles[], 1)) { writeln(d); }
	}
	}

Output 1:

C:\Temp\TEAM\BACKUP\dir1
C:\Temp\TEAM\BACKUP\DND3
C:\Temp\TEAM\BACKUP\dir2  - Duplicate
C:\Temp\TEAM\BACKUP\dir2  - Duplicate
C:\Temp\TEAM\EXPORT\DND6

Output 2:
C:\Temp\TEAM\BACKUP\dir1
C:\Temp\TEAM\BACKUP\DND3
C:\Temp\TEAM\BACKUP\dir2  - Duplicate
C:\Temp\TEAM\BACKUP\dir2  - Duplicate


C:\Temp\TEAM\EXPORT\DND6  - Missing

From,
Vino.B


More information about the Digitalmars-d-learn mailing list