digitalmars.D.learn - Retrieve the data of all the threads together once all threads are
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
Aug 26 2017
On Saturday, 26 August 2017 at 17:38:37 UTC, Vino.B wrote:
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
Hi All,
Was able to find a solution, but the output writes additional
empty lines., request your help on how to print without the empty
lines.
Program:
import std.stdio;
import std.parallelism;
import std.algorithm;
import std.string;
string Data;
auto Textarr = [ "Welcome", "Home" ];
string endresult;
string fn (string text)
{ return text; }
void main ()
{
string text;
auto endresult = taskPool.workerLocalStorage(text);
foreach ( i; parallel(Textarr[0 .. $], 1))
{
auto Task = task(&fn, i);
Task.executeInNewThread();
auto TaskData = Task.workForce;
endresult.get ~= TaskData;
}
foreach (i; sums.toRange)
{ writeln(i); }
}
Output:
C:\Users\admin\Desktop\Script>rdmd test.d
Welcome
Home
C:\Users\admin\Desktop\Script>
Aug 26 2017
On Saturday, 26 August 2017 at 18:26:30 UTC, vino wrote:On Saturday, 26 August 2017 at 17:38:37 UTC, Vino.B wrote:Hi All, Thank you very much issue resolved.[...]Hi All, Was able to find a solution, but the output writes additional empty lines., request your help on how to print without the empty lines. [...]
Aug 27 2017








Vino.B <vino.bheeman hotmail.com>