Retrieve the data of all the threads together once all threads are completed in a task pool
    Vino.B via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat Aug 26 10:38:37 PDT 2017
    
    
  
Hi,
   Can some one provide me an example of how to wait for all the 
threads to be completed in a taskPool and then retrieve the data 
of all the threads together instead of getting the data of each 
threads(after successfully executed). For example, the below test 
program outputs only one string "Welcome" but not the string 
"Home".
import std.stdio;
import std.parallelism;
string Data;
auto Textarr = [ "Welcome", "Home" ];
string fn (string text)
{ return text; }
string Submain ()
{
  foreach ( i; taskPool.parallel(Textarr[0 .. $], 1))
    {
	auto Task = task(&fn, i);
	Task.executeInNewThread();
	auto TaskData = Task.workForce;
	Data ~= TaskData;
   }
   return Data;
}
void main ()
{
  Submain;
  writeln(Data[0 .. $]);
}
From,
Vino.B
    
    
More information about the Digitalmars-d-learn
mailing list