Parallelization of a large array

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 10 15:37:29 PDT 2015


On 03/10/2015 03:16 PM, Meta wrote:

 > Just add a condition variable.
 >
 > import std.stdio;
 > import std.algorithm;
 > import std.parallelism;
 >
 > void main() {
 >
 >      int b = 2;
 >
 >      auto a = [1, 2, 2, 3];
 >
 >      if (find(a, b).length != 0)
 >          writeln("Yes_");
 >
 >      auto found = false;
 >
 >      foreach (elem; a.parallel)
 >          if (!found && elem == b)
 >          {
 >              writeln("Yes");
 >              found = true;

I thought about the same solution but then realized that it's a race 
condition, which needs to be taken care of. It's true that the value 
always changes from false to true but still...

 >          }
 > }

Ali



More information about the Digitalmars-d-learn mailing list