Thread Function does not executes

Vino vino.bheeman at hotmail.com
Mon Mar 5 13:50:28 UTC 2018


Hi All,

   Request your help, I have 3 functions such as below, I am 
calling these function using another function ptManage which 
executes these function's in parallel as each of the below 3 
function run's on 10 - 12 different file systems, The issue is as 
below

Issue:

Most of the time the program executes perfectly, some time the 
function 2 is skipped, after analysis further I was able to find 
that if the 1st and 3rd functions(deleteFile, SizeDir) completes 
before the 2nd function(deleteAgedDir) then it skips, meaning the 
program is not waiting for all the thread to be completed before 
exiting the main. so any help on this would be much appreciated. 
Ti does not throw any exception or error the program exits' 
smoothly.

Function:
deleteFile : Delete file after a certain date
deleteAgedDir : Delete folder after a certain date
SizeDir   : Finde Size of folder after a certain date

Ex:
auto deleteFile (string FFs, int AgeSize) { }

auto deleteAgedDir (string FFs, int AgeSize) { }

auto SizeDir (string FFs, int AgeSize) {

auto TP = new TaskPool(TL);
foreach (d; TP.parallel(dFiles[],1)) {
Thread.sleep(5.seconds); TP.finish;
  }
}

void ptManage(T)(T function(string, string, int) coRoutine, 
Array!string Dirlst, int AgeSize) {
alias scRType = typeof(coRoutine(string.init, string.init, 
int.init));
auto PFresult = taskPool.workerLocalStorage!scRType();
ReturnType!coRoutine rData;

foreach (string FFs; parallel(Dirlst[0 .. $],1)) { PFresult.get 
~= coRoutine(FFs.strip, Step, AgeSize); }
foreach(i; PFresult.toRange) { rData ~= i[][]; }
writeln(rData[]);
}

Void main() {

ptManage(&deleteFile, CleanDirlst, AgeSize1);
ptManage(&deleteAgedDi, AgedDirlst, AgeSize2);
ptManage(&SizeDir, AgeSize3);
	}	


From,
Vino.B


More information about the Digitalmars-d-learn mailing list